将居中标签添加到 bargraph.CI

Adding centered labels to bargraph.CI

我已经在这个问题上工作了一段时间,现在无济于事,现在我向大家求助help/advice。总体目标是从 Tukey HSD 函数中获取成对比较输出组,并将它们直接添加到分组条形图中。我对这些比较进行了多次迭代,因此理想的目标是在我 运行 脚本时自动设置此中心 - 如果可能,不要基于坐标进行手动定位。到目前为止,我有一个可用的 bargraph.CI 脚本、一个可用的 ANOVA 和一个可用的 post-hov 脚本 - 现在我只需要它们都能很好地协同工作。我面临的问题是 Tukey HSD 组标签没有与图形的条对齐(即输出顺序与图形顺序不对应)并且它们没有居中。请参阅我的示例脚本后生成的 outputs/graph。感谢您提供的所有帮助!!

一些示例数据: https://www.dropbox.com/s/ulpgrmv731yc2aw/CFLold.csv?dl=0

我确实有 "reputation" 到 post 的示例图片我目前拥有的是一张:

https://www.dropbox.com/s/5v7kgunapufk48t/Untitled.tiff?dl=0

这是我目前所拥有的:

library(sciplot)
library(agricolae)
mod.li <- aov(BA_Li ~ Year, CFL.old)
HSD.li <- HSD.test(mod.li,"Year", alpha = 0.05, group=TRUE, console=TRUE, main="Live Basal Area")

bg.li <- with(CFL.old, bargraph.CI(x.factor=Year, response=BA_Li,ylim= c(0,800),
              lc=FALSE, err.width = .03, xlab="Year of SB Outbreak", ylab = "Li (m2/ha)",
              x.leg=3.3, cex.leg=1, cex.names=1, cex.lab = 1,family = "Times",
              ci.fun=function(x) {c(mean(x) - 1.96*se(x), mean(x) + 1.96*se(x))}))
text(x=CFL.old$Year, labels=as.character(HSD.li$groups$M),cex=1,pos=3, xpd=T, family="Times")

不是你问的,但这是使用 ggplot 的解决方案。

library(ggplot2)
ggplot(CFL.old, aes(x=factor(Year), y=BA_Li)) + 
  stat_summary(fun.data=function(y)c(ymax=mean(y)+1.96*se(y),ymin=0), geom="errorbar", width=0.1)+
  stat_summary(fun.y=mean, geom="bar", fill="grey70", color="black")+
  geom_text(data=HSD.li$groups, aes(x=sub("\s+","",trt), y=0, label=M), vjust=-1)+
  coord_cartesian(ylim=c(-2,100), )+
  labs(x="Year of SB Outbreak", y="Li (m2/ha)") +
  theme_bw()+theme(panel.grid=element_blank())

你几乎是正确的。

你应该写

text(x = bg.li$xvals, labels = as.character(HSD.li$groups$M), cex = 1, pos = 3, xpd = T, family = "Times")

查看 bg.li

的 return 值