[英]Can I get boxplot notches in ggplot2?
Yes, I know it's been around, I've also found Hadley's answer on google groups that there is no notches yet for ggplot2
boxplots. 是的,我知道它已经存在,我也发现Hadley在google网上的答案是
ggplot2
图还没有缺口。 So my question is twofold: Has this changed (there's a native implementation of notches already) and if not is there something one could do about it. 所以我的问题是双重的:这已经改变了(已经有一个本地的凹口实现),如果没有,那么可以做些什么。
I mean I do not need the notch optic, representing the confidence bounds by some shaded area that is suitably placed in another layer over the boxplot, would look nice, too. 我的意思是我不需要缺口光学元件,代表一些阴影区域的置信区间,它适合放置在盒子图上的另一层中,看起来也不错。
Also added a screenshot because I heard a graphics question is never complete without the graphic 还添加了一个屏幕截图,因为我听说没有图形,图形问题永远不会完整
Update In addition to the options detailed below, version 0.9.0 of ggplot2 includes this feature in geom_boxplot
. 更新除了下文详述的选项,GGPLOT2的0.9.0版本包含此功能
geom_boxplot
。 Examining ?geom_boxplot
reveals a notch
and notchwidth
argument: 检查
?geom_boxplot
显示notch
和notchwidth
参数:
+ geom_boxplot(notch = TRUE, notchwidth = 0.5)
Not elegant graphics but here is an example: 不是优雅的图形,但这是一个例子:
# confidence interval calculated by `boxplot.stats`
f <- function(x) {
ans <- boxplot.stats(x)
data.frame(ymin = ans$conf[1], ymax = ans$conf[2])
}
# overlay plot (upper panel below)
p <- ggplot(iris, aes(Species, Sepal.Length)) + geom_boxplot() +
stat_summary(fun.data = f, geom = "linerange", colour = "skyblue", size = 5)
p
# base graphics (lower panel below)
boxplot(Sepal.Length ~ Species, data = iris, notch = TRUE)
you can change the apparence of CI bar by tweaking the arguments of stat_summary
. 你可以通过调整
stat_summary
的参数来改变CI栏的stat_summary
。
crossbar version: 横杆版本:
f <- function(x) {
ans <- boxplot.stats(x)
data.frame(ymin = ans$conf[1], ymax = ans$conf[2], y = ans$stats[3])
}
p <- ggplot(iris, aes(Species, Sepal.Length)) +
geom_boxplot(width = 0.8) +
stat_summary(fun.data = f, geom = "crossbar",
colour = NA, fill = "skyblue", width = 0.8, alpha = 0.5)
p
It may be interesting that on the ggplot2-dev mailing list a post concerning notched box plots has been posted. 可能有趣的是,在ggplot2-dev邮件列表 中 ,已经发布了一个关于缺口 框图的帖子。
You can find the development page on github . 您可以在github上找到开发页面。 The package may be installed via:
包装可以通过以下方式安装:
# install.packages("devtools")
library(devtools)
install_github("ggplot2")
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.