[R] Need help plotting

Ebert,Timothy Aaron tebert @end|ng |rom u||@edu
Thu Sep 22 04:06:38 CEST 2022


Yes, but if you want to learn R (or relearn R) it would be better for you to decompress the code.
You know what b looks like so add the next step. If you want to be able to see the original then save the output to another data frame.
New_df <- b %>%
    mutate(Dtime = paste(Sys.Date(), Dtime),
                  Dtime = as.POSIXct(Dtime))

What do you have now?
Then add the next pipe %>% and code until the next %>%. 
When you look at the dataframe after reshape() it will be very obvious, though if you still have questions please ask.

Tim

-----Original Message-----
From: R-help <r-help-bounces using r-project.org> On Behalf Of DFP
Sent: Wednesday, September 21, 2022 6:35 PM
To: Rui Barradas <ruipbarradas using sapo.pt>; r-help using r-project.org
Subject: Re: [R] Need help plotting

[External Email]

As I said, the lines below that you provided worked well for me. Can you explain what this line does?:

# reshape to long format
    pivot_longer(-Dtime, names_to = "NO2") %>%

-------------------------------------------------

library(ggplot2)
library(dplyr)
library(tidyr)

b %>%
    mutate(Dtime = paste(Sys.Date(), Dtime),
                  Dtime = as.POSIXct(Dtime)) %>%
    select(Dtime, DNO2, MNO2) %>%
    # reshape to long format
    pivot_longer(-Dtime, names_to = "NO2") %>%
    # now plot
    ggplot(aes(Dtime, value, color = NO2)) +
    geom_line() +
    geom_point() +
    scale_color_manual(values = c("orange", "skyblue")) +
    # make datetime labels
    scale_x_datetime(date_breaks = "1 mins", date_labels = "%H:%M") +
    theme_bw()


        [[alternative HTML version deleted]]

______________________________________________
R-help using r-project.org mailing list -- To UNSUBSCRIBE and more, see
https://nam10.safelinks.protection.outlook.com/?url=https%3A%2F%2Fstat.ethz.ch%2Fmailman%2Flistinfo%2Fr-help&data=05%7C01%7Ctebert%40ufl.edu%7C2e922af564854b594aae08da9c21a172%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637993965506049641%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=gnPZJIDTjVr8cv9s3foPjzYYUXWYX5Y18%2FLRKQpXyp4%3D&reserved=0
PLEASE do read the posting guide https://nam10.safelinks.protection.outlook.com/?url=http%3A%2F%2Fwww.r-project.org%2Fposting-guide.html&data=05%7C01%7Ctebert%40ufl.edu%7C2e922af564854b594aae08da9c21a172%7C0d4da0f84a314d76ace60a62331e1b84%7C0%7C0%7C637993965506049641%7CUnknown%7CTWFpbGZsb3d8eyJWIjoiMC4wLjAwMDAiLCJQIjoiV2luMzIiLCJBTiI6Ik1haWwiLCJXVCI6Mn0%3D%7C3000%7C%7C%7C&sdata=aLDvzRXPm3MSdulLOCbKDUSL59bO3RvhwAAkGl%2B%2BJ8M%3D&reserved=0
and provide commented, minimal, self-contained, reproducible code.



More information about the R-help mailing list