[英]How to make a boxplot with the 5 points summary ready with ggplot2?
Dummy data 虚拟数据
d = data.frame(type=LETTERS[1:3], ymin=c(1,1.1,2), lower=c(1.5,1.5,4), middle=c(1.6,1.8,4.5), upper=c(2,2.1,7), ymax=c(2.5, 2.6, 10))
type ymin lower middle upper ymax
1 A 1.0 1.5 1.6 2.0 2.5
2 B 1.1 1.5 1.8 2.1 2.6
3 C 2.0 4.0 4.5 7.0 10.0
Goal 目标
I would like to make a boxplot with ggplot2
with the kind of data showed above, where I already 5 the positions of the 5 points for the boxplot. 我想用上面显示的数据用
ggplot2
创建一个箱线图,其中我已经为箱线图5个点的5个位置了。 In the above case, there must have 3 different boxes. 在上述情况下,必须有3个不同的框。
What I tried 我尝试了什么
ggplot(d, aes(x=type, y=middle)) + stat_summary(geom="boxplot", list(ymin=ymin, lower=lower, middle=middle, upper=upper, ymax=ymax))
and 和
ggplot(d, aes(x=type, y=middle)) + geom_boxplot(ymin=ymin, lower=lower, middle=middle, upper=upper, ymax=ymax)
but both fail. 但都失败了。
Like this: 像这样:
ggplot(d, aes(x=type)) +
geom_boxplot(aes(ymin=ymin, lower=lower, middle=middle, upper=upper, ymax=ymax),
stat = "identity")
You were close with the second try, but you needed to put the arguments in an aes
, and to add stat = "identity"
to the boxplot (so that it wouldn't try to apply the summarizing itself). 您已经完成第二次尝试了,但是您需要将参数放在
aes
,并将stat = "identity"
添加到箱线图中(这样它就不会尝试应用摘要本身)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.