r - 如何在 ggplot2 (R) 中定义误差线的宽度?

标签 r ggplot2 confidence-interval

我有以下要绘制的数据。我正在尝试更改错误栏的宽度,但我遇到了一个错误,提示 Width not defined。设置 position_dodge(width = ?)。我试着做 position_dodge.. 但它没有帮助。有什么建议吗?

library(ggplot2)

time <- c("t1","t1","t1","t1","t1","t1","t2","t2","t2","t2","t2","t2")
species <- c(1,1,1,2,2,2,1,1,1,2,2,2)
value <- c(1,2,3,11,12,13,4,5,6,11,12,13)

df <- data.frame(time, species,value)
df$time <- as.factor(df$time)
df$species <- as.factor(df$species)

ggplot(df,aes(x=time, y=value, color = species, group = species)) + # Change fill to color
  theme_bw() + 
  geom_point() + 
  stat_summary(fun.y=mean, position = "dodge") + 
  stat_summary(
    geom="errorbar", 
    fun.data= mean_cl_boot, 
    width = 0.1, size = 0.2, col = "grey57") + 
  # Lines by species using grouping
  stat_summary(aes(group = species), geom = "line", fun.y = mean) +
  ylab("Fitness")

最佳答案

Position dodge 用于在数据点重叠时显示所有数据点,我不确定这在您的示例中是否有用,如果您的数据不重叠,您可能会发现仅删除此参数即可解决问题。保持不变可以解决问题:

pd<-position_dodge(0.5)
  ggplot(df,aes(x=time, y=value, color = species, group = species)) + # Change fill to color
  theme_bw() + 
  geom_point(position = pd) + 
  stat_summary(fun.y=mean, position = pd) + 
  stat_summary(
    geom="errorbar", 
    fun.data= mean_cl_boot, 
    width = 0.1, size = 0.2, col = "grey57",
    position = pd) + 
  # Lines by species using grouping
  stat_summary(aes(group = species), geom = "line", fun.y = mean, position = pd) +
  ylab("Fitness")

刚刚编辑以防止一切 split 。

关于r - 如何在 ggplot2 (R) 中定义误差线的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54817836/

相关文章:

r - 与 adaptIntegrate 的集成不一致

R:使用自定义顺序按名称重新排序数字向量

r - 使用 r 缩放水平和垂直线/刻度图( map )

r - 以限制为中心的ggplot2多边形世界地图给出了有趣的边缘

r - 从facet_wrap更改标题的字体大小

r - 在散点图中绘制 95% 置信限

r - 如何在ggplot中绘制虚线95%置信区间

r - 合并 data.frame 中的两行

r - 我可以避免在 R 中使用 `eval(parse())` 定义函数 `polynomial()` 吗?

r - 具有箱线图类型分组的点范围图