【问题标题】:Explain why `position_dodge(width=0.9)` centers the errorbar? [duplicate]解释为什么 `position_dodge(width=0.9)` 使误差条居中? [复制]
【发布时间】:2014-09-29 18:34:39
【问题描述】:

这是直接取自ggplot2 documentation的代码

df <- data.frame(
  trt = factor(c(1, 1, 2, 2)),
  resp = c(1, 5, 3, 4),
  group = factor(c(1, 2, 1, 2)),
  se = c(0.1, 0.3, 0.3, 0.2)
)
df2 <- df[c(1,3),]

# Define the top and bottom of the errorbars
limits <- aes(ymax = resp + se, ymin=resp - se)

p <- ggplot(df, aes(fill=group, y=resp, x=trt))
p + geom_bar(position="dodge", stat="identity")
# 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)
p + geom_bar(position=dodge) + geom_errorbar(limits, position=dodge, width=0.25)

我不明白为什么position_dodge(width=0.9),尤其是0.9?这个数字怎么算?

【问题讨论】:

    标签: r ggplot2


    【解决方案1】:
    # we need to specify how wide the objects we are dodging are
    

    我很确定 0.9 是 geom_bar 的默认宽度。

    如果您使用 geom_bar(position="dodge", stat="identity", width=0.5) 重做示例,则必须将 dodge 更改为 0.5 以使其看起来不错。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-02
      • 2017-12-02
      • 1970-01-01
      • 2020-04-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多