【发布时间】:2019-04-21 16:50:20
【问题描述】:
我有一个名为“绑定”的 df,其中包含不同时间间隔(9_10,10_11,11_12 = 列名)的值(我找到了多少动物)。最后两行是区间内气温的平均值和标准差,来自另一个df。
9_10 10_11 11_12 2.1 5.1 不适用 4.23 2.1 9.2 北美 3.2 5.6 18.56 20.45 23.56 5.67 5.12 5.78
不过我的df要长很多..
现在,我想制作一个箱线图,其中的列名定义 x 轴,而箱线由找到的动物的值组成。平均值应打印为一条线(可能带有第二个 y 轴),其中 sd 作为误差线。不知何故,尽管这些线会位于箱线图之外,因为它们不是来自相同的数据:
https://peltiertech.com/images/2011-06/BoxPlotH5a.png (对不起,这里不允许发图片)
Alpha、Beta 等将是 9_10、10_11 等。
我已经尝试过这个(除其他外):
t <- ggplot(stack(bound[1:3,]), aes(x=ind, y=values))
t <- t + geom_boxplot(outlier.shape=NA,fill="grey", color="black")
t <- t + coord_cartesian(ylim = c(0, 20))
t <- t + scale_x_discrete(name = NULL, labels=c("09:00 - 09:59","10:00 - 10:59","11:00 - 11:59"))
t <- t + scale_y_continuous(name = "animals found per hour")
t <- t + geom_line(stack(bound[4,]),aes(x=ind, y=values))
t <- t + scale_y_continuous(sec.axis = sec_axis(~.), name = "mean air temperature")
这段代码给了我一个很好的箱线图,就像我想要它用于找到动物数量的行一样。但是空气温度线没有出现,我不知道 ggplot 是否能够做到。在我看来,它在箱线图中的某处垂直绘制了一条线,但在箱线图之间没有水平线。
谁能帮帮我?
【问题讨论】: