yxh13666的个人博客分享 http://blog.sciencenet.cn/u/yxh13666

博文

一种分组柱状图标显著性LSD检验字母(abc)的方法 r代码

已有 1519 次阅读 2022-12-16 10:05 |系统分类:科研笔记


S<-data.frame(read_excel("总数据.xlsx",1))

S$treat = factor(S$treat, levels=c("CK","N","P","NP"))

pc1<-subset(S,acid=="no")

pc2<-subset(S,acid=="yes")

model1<-aov(pPFrich~treat,data=pc1)

model2<-aov(pPFrich~treat,data=pc2)

out1<-data.frame(cbind(rownames(LSD.test(model1,"treat" )$groups),LSD.test(model1,"treat" )$groups[,2]))#显著性和位置

out2<-data.frame(cbind(rownames(LSD.test(model2,"treat" )$groups),toupper(LSD.test(model2,"treat" )$groups[,2])))#显著性和位置


c<-data.frame()

for (i in out1$X1) {

  a<-subset(pc1,treat==i)

  b<-mean(a$pPFrich)+sd(a$pPFrich)/sqrt(length(a$pPFrich))

  c<-rbind(c,b)

}

colnames(c)<-"po"#字母的位置

out1<-cbind(out1,c)

c1<-data.frame()

for (i in out2$X1) {

  a1<-subset(pc2,treat==i)

  b1<-mean(a1$pPFrich)+sd(a1$pPFrich)/sqrt(length(a1$pPFrich))

  c1<-rbind(c1,b1)

}

colnames(c1)<-"po"#字母的位置

out2<-cbind(out2,c1)

d<-rbind(c,c1)

posi<-(cbind(rbind(out1,out2),d))


e<-data.frame()

for (i in match(pc1$treat,out1$X1)) {

  a<-out1[i,2:3]

  e<-rbind(e,a)

}

colnames(e)<-c("sig","po")#字母文本和显著性字母


e1<-data.frame()

for (i in match(pc2$treat,out2$X1)) {

  a<-out2[i,2:3]

  e1<-rbind(e1,a)

}

colnames(e1)<-c("sig","po")#字母文本和显著性字母

S<-cbind(rbind(e,e1),rbind(pc1,pc2))

p<-ggplot(S,aes(x=treat,y=pPFrich ,fill=acid))+stat_summary(geom = "bar",fun = "mean",

position = position_dodge(0.6),width=0.6, color="black")+stat_summary(geom = "errorbar",

fun.min = ebbottom,

fun.max = ebtop,

position = position_dodge(0.6),

width=0.2)+ geom_text(aes(x=treat,y=po+po*0.04,label = sig),position = position_dodge(0.6))+theme(legend.position = c('none')

,axis.text.y=element_text(angle=90),axis.title.x = element_blank())+scale_y_continuous(limits = c(0,8),expand = c(0, 0))+scale_fill_manual(values=c("#008B00","#FF7F24"))

p




https://blog.sciencenet.cn/blog-3485408-1368069.html


收藏 IP: 117.150.0.*| 热度|

0

该博文允许注册用户评论 请点击登录 评论 (0 个评论)

数据加载中...
扫一扫,分享此博文

Archiver|手机版|科学网 ( 京ICP备07017567号-12 )

GMT+8, 2024-5-3 10:37

Powered by ScienceNet.cn

Copyright © 2007- 中国科学报社

返回顶部