是的,我知道它已经存在了,我还在 Google 群组中找到了 Hadley 的回答,即 ggplot2
还没有缺口。箱线图。所以我的问题是双重的:这是否改变了(已经有一个缺口的本地实现),如果没有,人们可以做些什么。
我的意思是我不需要缺口光学元件,通过适当放置在箱线图的另一层中的某个阴影区域来表示置信界限,看起来也不错。
还添加了一个屏幕截图,因为我听说没有图形就永远不会完成图形问题
最佳答案
更新
除了下面详述的选项之外, 的 0.9.0 版ggplot2 在 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
的参数来更改 CI 栏的外观。 .横杆版本:
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
关于r - 我可以在 ggplot2 中获得箱线图凹口吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8134699/