【问题标题】:How to adjust width of errorbar created with stat_summary_bin?如何调整使用 stat_summary_bin 创建的误差条的宽度?
【发布时间】:2017-02-23 14:37:45
【问题描述】:

我使用以下代码创建了一个分组条形图。我想将错误栏的宽度调整为一半 当前宽度。但是,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)

【问题讨论】:

    标签: r ggplot2


    【解决方案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)
    

    【讨论】:

    • 虽然这产生了我想要的图像,但这不适用于stat_summary_bin。你有什么想法吗?
    • 抱歉,目前没有,也许是其他人?
    猜你喜欢
    • 2014-03-18
    • 2017-10-22
    • 2021-07-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-02-03
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多