我使用以下代码创建了一个分组的条形图。我想将errorbar的宽度调整为一半
当前宽度。但是,width = 0.5
对结果没有影响。我该怎么做?
library(ggplot2)
# ggplot2_2.2.1
df <- iris
set.seed(1)
df$group <- sample(c('I', 'II'), nrow(df), replace = T)
ggplot(df, aes(x = group, y = Sepal.Width, fill = Species)) +
stat_summary_bin(fun.data = "mean_cl_normal",
geom = 'bar', position = 'dodge') +
stat_summary_bin(fun.data = "mean_cl_normal",
geom = 'errorbar', position = 'dodge', width = 0.5)
答案 0 :(得分:1)
# ?geom_errorbar, see bottom
# Because the bars and errorbars have different widths
# we need to specify how wide the objects we are dodging are
dodge <- position_dodge(width = 0.9)
ggplot(df, aes(x = group, y = Sepal.Width, fill = Species)) +
stat_summary(fun.data = "mean_cl_normal", geom = 'bar', position = dodge) +
stat_summary(fun.data = "mean_cl_normal", geom = 'errorbar', position = dodge, width = 0.5)