简体   繁体   English

Plot 多行 ggplot2 从

[英]Plot multiple lines in ggplot2 from

I want to produce ax,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.我想生产 ax,y plot,使用 ggplot 或其他任何方法,下表中显示了多个列:它们应该与 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.平均值是我的 y 值,SD 作为我的误差线,而列 Day 也应该作为我的 x 值作为时间线。 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).最后它们应该是 8 行(如果找到数据)。

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?我是否必须生成另一个具有 Day、SoilNumber 和 Sample 组合字符的列?

Thanks for any help.谢谢你的帮助。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM