更新
以下に詳述するオプションに加えて、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)
の引数を微調整することで、CIバーの外観を変更できます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
