我有一个看起来像这样的数据框:
> head(DOData)
Date Site1 Site2 Site3 Site4 Site5 Months
1 1/1/2012 1.07 3.32 11.35 6.26 5.39 January
2 1/2/2012 1.24 3.08 10.69 6.57 6.59 January
3 1/3/2012 1.94 2.69 11.86 6.23 6.23 January
4 1/4/2012 0.81 3.50 11.47 4.67 5.94 January
5 1/5/2012 1.41 3.11 10.38 7.44 5.40 January
6 1/6/2012 2.73 3.28 11.11 6.15 6.22 January
.
.
.
361 12/26/2012 3.54 3.86 12.67 5.44 6.03 December
362 12/27/2012 2.05 3.42 10.27 6.05 7.10 December
363 12/28/2012 3.59 2.96 11.10 6.71 5.68 December
364 12/29/2012 1.81 3.57 11.20 7.20 7.71 December
365 12/30/2012 4.03 2.00 11.07 7.15 5.93 December
366 12/31/2012 1.93 2.03 11.90 6.06 8.46 December
例如,一年有5个站点的数据,每天有一行。
我想boxplot
使用五个站点作为因素,为每个月创建一些ggplot2数据。我想我可以将所有数据放在一个列中,然后为站点名称添加一个新列,但是随后我仍然需要以某种方式选择各个月。我想知道,我是否真的需要重新组织数据,还是有某种方法可以将列用作因素?谢谢你的帮助!
如果您重新排列数据框,将会更加容易。这可以通过以下reshape2
软件包来完成:
library(reshape2)
DOData2 <- melt(DOData)
现在,情节的创建非常简单:
library(ggplot2)
ggplot(DOData2) +
geom_boxplot(aes(y = value, x = Months, colour = variable))
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句