0

I want to produce a x,y plot, with ggplot or whatever works, with multiple columns represented in the table below: They should be grouped together with Day, Soil Number, Sample. Mean is my y value and SD as my errorbar while the column Day should also serve as my x value as a timeline. How do I manage this?

Results_CMT
# A tibble: 22 x 5
# Groups:   Day, Soil_Number [10]
     Day Soil_Number Sample   Mean     SD
   <int>       <int> <chr>   <dbl>  <dbl>
 1           3.84   0.230
 2     0       65872 R       4.82   0.679
 3     1       65871 R       3.80   1.10 
 4     1       65872 R       3.24   1.61 
 5     3       65871 fLF    NA     NA    
 6     3       65871 HF      1.73   0.795
 7     3       65871 oLF     0.360  0.129
 8     3       65871 R       3.13   1.36 
 9     3       65872 fLF    NA     NA    
10     3       65872 HF      1.86   0.374
# ... with 12 more rows

At the end their should be 8 Lines (if data is found).

65871 R
65871 HF
65871 fLF
65871 oLF
65872 R
65872 HF
65872 fLF
65872 oLF

Do I have to produce another Column with a combined character of Day, SoilNumber and Sample?

Thanks for any help.

kath
  • 7,624
  • 17
  • 32
oliebisc
  • 15
  • 2
  • Hey, please have another look at your post and reformat it / make it a reproducible example. This makes it much easier to understand your wishes and help you. Here is an explanation for how to do this: https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example?noredirect=1&lq=1 – Mojoesque Oct 09 '19 at 13:24
  • Oh yeah sorry. Was my first post but i got help so I will just try to keep an eye on it when I post the next question :) thank you! – oliebisc Oct 10 '19 at 08:19

1 Answers1

0

Try this:

library(ggplot2)

ggplot(Results_CMT, aes(x = Day, y = Mean, colour = interaction(Sample, Soil_Number))) +
  geom_line() +
  geom_errorbar(aes(ymin = Mean-SD, ymax = Mean+SD), width = .2)
Aron Strandberg
  • 3,040
  • 9
  • 15
  • 1
    That worked nicely! I could work with it and made it a bit more precise because there was too much chaos in the graph. thank u very much. Been looking for a function like this interaction(). Thank you! – oliebisc Oct 10 '19 at 08:18