Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/80.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 条形图中的重要线_R_Ggplot2 - Fatal编程技术网

R 条形图中的重要线

R 条形图中的重要线,r,ggplot2,R,Ggplot2,我刚刚得到了一个关于如何在箱线图中添加一条重要线的答案,我认为这对条形图来说是一样的,但是,尽管绘制图表时没有错误警告,但没有重要线。 我需要添加3个有效行(EE-CTL、EE-ECM和ERM-CTL) 我想这与我根据之前计算的平均值和SEM绘制图表的情况有关,而不是根据数据: structure(list(Treatment = c("ECM", "ERM", "EE", "CTL"), Mean = c(8.01

我刚刚得到了一个关于如何在箱线图中添加一条重要线的答案,我认为这对条形图来说是一样的,但是,尽管绘制图表时没有错误警告,但没有重要线。 我需要添加3个有效行(EE-CTL、EE-ECM和ERM-CTL)

我想这与我根据之前计算的平均值和SEM绘制图表的情况有关,而不是根据数据:

structure(list(Treatment = c("ECM", "ERM", "EE", "CTL"), Mean = c(8.01025737179488, 
8.58786182336182, 9.38446207264958, 7.67579786324786), SD = c(1.91613571112389, 
1.9575684010905, 2.07777394688292, 1.99520762598057), SE = c(0.216959646000991, 
0.221650974332193, 0.235261572219951, 0.225912777324796)), row.names = c(NA, 
-4L), class = c("tbl_df", "tbl", "data.frame"))
很抱歉,我不得不这么快再问一次。我希望最后的解决办法在这里奏效。 我还尝试添加一条几何线,与我最初尝试的方法相同,但它产生了相同的错误

你能帮忙吗


与此同时,我找到了一个解决办法。它不优雅,但很管用。我仍然很乐意学习更好的版本

ggplot(soiltemp, aes(x=Treatment, y=Mean)) + 
  geom_bar(stat = "identity", color = "black",
           fill=c("#c9df8a", "#77ab59", "#36802d", "#f0f7da"))+
  scale_x_discrete(limits=c("ECM","ERM","EE","CTL"))+
  labs(x="Treatment", y="Mean Temperature [°C]") +
  coord_cartesian(ylim = c(7, 12))+
  geom_errorbar(aes(ymin=Mean-SE, ymax=Mean+SE), width=.2,
                position=position_dodge(.9))+
  annotate("segment", x=2, xend=4, y=9.8, yend=9.8)+
  annotate("segment", x=2, xend=2, y=9.6, yend=9.8)+
  annotate("segment", x=4, xend=4, y=9.6, yend=9.8)+
  annotate("text", x=3, y=10, label="*", size=6)

ggplot(soiltemp, aes(x=Treatment, y=Mean)) + 
  geom_bar(stat = "identity", color = "black",
           fill=c("#c9df8a", "#77ab59", "#36802d", "#f0f7da"))+
  scale_x_discrete(limits=c("ECM","ERM","EE","CTL"))+
  labs(x="Treatment", y="Mean Temperature [°C]") +
  coord_cartesian(ylim = c(7, 12))+
  geom_errorbar(aes(ymin=Mean-SE, ymax=Mean+SE), width=.2,
                position=position_dodge(.9))+
  annotate("segment", x=2, xend=4, y=9.8, yend=9.8)+
  annotate("segment", x=2, xend=2, y=9.6, yend=9.8)+
  annotate("segment", x=4, xend=4, y=9.6, yend=9.8)+
  annotate("text", x=3, y=10, label="*", size=6)