r - 我可以在 ggplot2 中获得箱线图凹口吗?

标签 r ggplot2 boxplot

是的,我知道它已经存在了,我还在 Google 群组中找到了 Hadley 的回答,即 ggplot2 还没有缺口。箱线图。所以我的问题是双重的:这是否改变了(已经有一个缺口的本地实现),如果没有,人们可以做些什么。

我的意思是我不需要缺口光学元件,通过适当放置在箱线图的另一层中的某个阴影区域来表示置信界限,看起来也不错。

还添加了一个屏幕截图,因为我听说没有图形就永远不会完成图形问题
enter image description here

最佳答案

更新
除了下面详述的选项之外, 的 0.9.0 版ggplot2 geom_boxplot 中包含此功能.正在检查 ?geom_boxplot揭示了 notchnotchwidth争论:

+ 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 栏的外观。 .

enter image description here enter image description here

横杆版本:
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

enter image description here

关于r - 我可以在 ggplot2 中获得箱线图凹口吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8134699/

相关文章:

r - 基于广播中播放的音乐流派分类

r - vtree 对象在 Markdown 中呈现,但不在四开本中呈现

r - 如何测试对象是否具有特定方法?

r - 几何段: Removed 1 rows containing missing values

r - 神秘的 R ggplot 错误 - list2env(成员,envir = e)中的错误

python - 如何使用seaborn绘制带有嵌套数据的时间序列箱线图?

r - 更改箱线图的布局并为其添加标签

r - 如何获取 R 文件并将文件中的所有变量存储在列表中

r - 在 R 中绘制列的箱线图

r - 如何在所有填充美学上使用 after_stat 到一个比例