0

I have huge dataset for which I need to create plot with all the temperature data for a time scale on the same plot. Now, the data frame consists of many repeats of the following structure: Name, Date, Temp, Name__1, Date__1, Temp__1,...

So for every line, I want to use 3 columns and then plot the next 3 columns. I don't know if it is possible to use some kind of loop for this. What I've been doing so far is the following:

ggplot(data = "name_of_mydatase") + 
  geom_line(mapping = aes(Date, Temp, col = Name)) +
  geom_line(mapping = aes(Date__1, Temp1, col = Name__1))

If I have to repeat this for every single temperature logger, the code would be endless and I know there are more elegant ways to do this but I just can't figure out a simpler ways. Can someone please help? Thank you so much!!!

neilfws
  • 32,751
  • 5
  • 50
  • 63
  • 2
    The idiomatic ggplot way would be to convert your data into long (aka "tidy") form first, so that the three series have their values in one shared column but their identification (eg Temp1, Temp2, etc.) in another column. https://tidyr.tidyverse.org/articles/tidy-data.html – Jon Spring Oct 15 '18 at 16:00
  • Welcome to Stack Overflow! Could you make your problem reproducible by sharing a sample of your data so others can help (please do not use `str()`, `head()` or screenshot)? You can use the [`reprex`](https://reprex.tidyverse.org/articles/articles/magic-reprex.html) and [`datapasta`](https://cran.r-project.org/web/packages/datapasta/vignettes/how-to-datapasta.html) packages to assist you with that. See also [Help me Help you](https://speakerdeck.com/jennybc/reprex-help-me-help-you?slide=5) & [How to make a great R reproducible example?](https://stackoverflow.com/q/5963269) – Tung Oct 15 '18 at 16:49

0 Answers0