将标准偏差添加到 R 中的 barplot()
Adding standard deviation to barplot() in R
在 R 中我有以下数据框:
Group mean sd
1 1 21.2 5.202563
2 2 28.4 6.113737
3 3 21.8 2.529822
我想创建一个条形图,其中均值和标准差作为均值顶部的箭头,如下例所示:
这是我目前的代码:
barCenters <- barplot(height = Ymeans12stdev$mean,main = "Average Time per Group",
xlab = "Group", ylab = "Time")
但是,我没有成功添加标准偏差条。谁能解决这个问题? :)
对于基础 R,您可以使用函数 arrows() :
barCenters <- barplot(height = Ymeans12stdev$mean,
main = "Average Time per Group", xlab = "Group", ylab = "Time")
arrows(barCenters, Ymeans12stdev$mean-Ymeans12stdev$sd,
barCenters, Ymeans12stdev$mean+Ymeans12stdev$sd,angle=90,code=3)
参数 angle=90
指定绘制 "flat" 箭头(即垂直箭头上方的水平条),参数 code=3
指定在箭头的两端绘制箭头垂线。您可以将参数 length
添加到 increase/reduce 箭头水平条的大小。
在 R 中我有以下数据框:
Group mean sd
1 1 21.2 5.202563
2 2 28.4 6.113737
3 3 21.8 2.529822
我想创建一个条形图,其中均值和标准差作为均值顶部的箭头,如下例所示:
这是我目前的代码:
barCenters <- barplot(height = Ymeans12stdev$mean,main = "Average Time per Group",
xlab = "Group", ylab = "Time")
但是,我没有成功添加标准偏差条。谁能解决这个问题? :)
对于基础 R,您可以使用函数 arrows() :
barCenters <- barplot(height = Ymeans12stdev$mean,
main = "Average Time per Group", xlab = "Group", ylab = "Time")
arrows(barCenters, Ymeans12stdev$mean-Ymeans12stdev$sd,
barCenters, Ymeans12stdev$mean+Ymeans12stdev$sd,angle=90,code=3)
参数 angle=90
指定绘制 "flat" 箭头(即垂直箭头上方的水平条),参数 code=3
指定在箭头的两端绘制箭头垂线。您可以将参数 length
添加到 increase/reduce 箭头水平条的大小。