解释为什么`position_dodge(width = 0.9)`中心错误栏?

时间:2014-09-29 18:34:40

标签: r ggplot2

此处的代码直接取自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?如何提出这个数字?

1 个答案:

答案 0 :(得分: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)重做这个例子,你必须将闪避改为0.5,让它看起来不错。