Do I need that read.table if the tst dataframe already exists in my system?? If so, why? -------------------------------------------------- Hello, You have to load the packages involved: library(dplyr) library(tidyr) library(ggplot2) then run the full sequence. Though this is not important, if you are pivotting columnns named y1 and y2, why not name the result just y? pivot_longer(-time, names_to = "y") And here is complete code, runs in a fresh R session. tst? <- read.table(text = " time y1 y2 1? 18:55 30 19 2? 18:56 30 19 3? 18:57 29 19 4? 18:58 31 19 5? 18:59 28 19 6? 19:00 28 19 7? 19:01 28 19 8? 19:02 28 19 9? 19:03 28 19 10 19:04 28 19 11 19:05 29 19 ", header = TRUE) library(dplyr) library(tidyr) library(ggplot2) tst %>% ?? mutate(time = paste(Sys.Date(), time), ????????? time = as.POSIXct(time)) %>% ?? select(time, y1, y2) %>% ?? # reshape to long format ?? pivot_longer(-time, names_to = "y") %>% ?? # now plot ?? ggplot(aes(time, value, color = y)) + ?? 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() Hope this helps, Rui Barradas [[alternative HTML version deleted]]
No you don't! I do! I don't have tst on my system. Rui Barradas ?s 22:11 de 22/09/2022, DFP escreveu:> Do I need that read.table if the tst dataframe already exists in my > system?? If so, why? > > -------------------------------------------------- > > Hello, > > You have to load the packages involved: > > > library(dplyr) > library(tidyr) > library(ggplot2) > > > then run the full sequence. Though this is not important, if you are > pivotting columnns named y1 and y2, why not name the result just y? > > > pivot_longer(-time, names_to = "y") > > > And here is complete code, runs in a fresh R session. > > > tst? <- read.table(text = " > time y1 y2 > 1? 18:55 30 19 > 2? 18:56 30 19 > 3? 18:57 29 19 > 4? 18:58 31 19 > 5? 18:59 28 19 > 6? 19:00 28 19 > 7? 19:01 28 19 > 8? 19:02 28 19 > 9? 19:03 28 19 > 10 19:04 28 19 > 11 19:05 29 19 > ", header = TRUE) > > library(dplyr) > library(tidyr) > library(ggplot2) > > tst %>% > ?? mutate(time = paste(Sys.Date(), time), > ????????? time = as.POSIXct(time)) %>% > ?? select(time, y1, y2) %>% > ?? # reshape to long format > ?? pivot_longer(-time, names_to = "y") %>% > ?? # now plot > ?? ggplot(aes(time, value, color = y)) + > ?? 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() > > > Hope this helps, > > Rui Barradas >
Hi David, No, read.table converts a text representation of data into a data frame object. Jim On Sat, Sep 24, 2022 at 2:29 AM DFP <dfpgnu at gmail.com> wrote:> > Do I need that read.table if the tst dataframe already exists in my > system? If so, why? > > -------------------------------------------------- > > Hello, > > You have to load the packages involved: > > > library(dplyr) > library(tidyr) > library(ggplot2) > > > then run the full sequence. Though this is not important, if you are > pivotting columnns named y1 and y2, why not name the result just y? > > > pivot_longer(-time, names_to = "y") > > > And here is complete code, runs in a fresh R session. > > > tst <- read.table(text = " > time y1 y2 > 1 18:55 30 19 > 2 18:56 30 19 > 3 18:57 29 19 > 4 18:58 31 19 > 5 18:59 28 19 > 6 19:00 28 19 > 7 19:01 28 19 > 8 19:02 28 19 > 9 19:03 28 19 > 10 19:04 28 19 > 11 19:05 29 19 > ", header = TRUE) > > library(dplyr) > library(tidyr) > library(ggplot2) > > tst %>% > mutate(time = paste(Sys.Date(), time), > time = as.POSIXct(time)) %>% > select(time, y1, y2) %>% > # reshape to long format > pivot_longer(-time, names_to = "y") %>% > # now plot > ggplot(aes(time, value, color = y)) + > 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() > > > Hope this helps, > > Rui Barradas > > [[alternative HTML version deleted]] > > ______________________________________________ > R-help at r-project.org mailing list -- To UNSUBSCRIBE and more, see > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide http://www.R-project.org/posting-guide.html > and provide commented, minimal, self-contained, reproducible code.