R - 如何在箱线图中显示均值,中位数,标准差,分位数

时间:2015-02-12 02:28:07

标签: r mean boxplot median quantile

有没有办法可以使用R在箱线图中显示“五个值”?

p0.3 = dbinom(0:60, 60, 0.3)
p0.5 = dbinom(0:60, 60, 0.5)
p0.8 = dbinom(0:60, 60, 0.8)
boxplot(p0.3,p0.5,p0.8,  names=c("0.3","0.5","0.8"),col=c("red","yellow","blue"),main = "Boxplot of Probability Distribution ", ylab = "Distribution Density", xlab = "Probability")

1 个答案:

答案 0 :(得分:0)

我不清楚您是否想要绘制符号或值本身。首先,您可以添加一些内容,如:

abline(h=mean(p0.3), col ="red");
points(sd(p0.3), pch=18, col ="red")

如果是第二个,您可以自己计算这些统计数据,然后将这些值添加为文本:

p0.3 = dbinom(0:60, 60, 0.3)
 p0.5 = dbinom(0:60, 60, 0.5)
p0.8 = dbinom(0:60, 60, 0.8)
 boxplot(p0.3,p0.5,p0.8,  names=c("0.3","0.5","0.8"),col=c("red","yellow","blue"),main = "Boxplot of Probability Distribution ", ylab = "Distribution Density", xlab = "Probability")

means <- mean(p0.3, na.rm = TRUE)

text(x=means, labels = means, y=0.01) # you will need to adjust y