是的,我知道它已经存在了,我还在谷歌群组上找到了哈德利的回答,即箱线图还没有缺口ggplot2
。所以我的问题是双重的:这是否改变了(已经有一个原生的缺口实现),如果没有,有什么可以做的。
我的意思是我不需要缺口光学元件,它通过一些阴影区域来表示置信范围,该阴影区域适当地放置在箱线图上的另一层中,看起来也不错。
还添加了一个截图,因为我听说一个图形问题没有图形就永远不完整
更新
除了下面详述的选项外,ggplot2的 0.9.0 版在geom_boxplot
. 检查?geom_boxplot
揭示了一个notch
和notchwidth
论点:
+ geom_boxplot(notch = TRUE, notchwidth = 0.5)
不是优雅的图形,但这里有一个例子:
# 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)
您可以通过调整stat_summary
.
横杆版本:
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
有趣的是,在ggplot2-dev 邮件列表上发布了一篇关于缺口箱形图的帖子。
你可以在github上找到开发页面。该软件包可以通过以下方式安装:
# install.packages("devtools")
library(devtools)
install_github("ggplot2")