在Rstudio中修改Tukey HSD 95%家庭式CL图

时间:2015-05-30 15:57:33

标签: r plot rstudio

我想知道如何改变Tukey HSD图的轴,这样我就可以缩短单词,使每个比较合适,而不是看起来很荒谬。

如果您可以帮助我更改轴标签,字体大小和颜色的代码,那将会有很大帮助。

在情节中有相当多的比较,所以我想通过改变它们的颜色来使重要的(比较间隔不在“0”线上)更突出。

`Gastropods = read.csv(file = "MaroubraZones.csv", header = TRUE)
boxplot(Abundance ~ Zone*Species,data = Gastropods, names = c("A.high", "A.mid", "A.low", "C.high", "C.mid", "C.low", "N.high", "N.mid", "N.low"))
Gastropods.ANOVA = aov(Abundance ~ Zone * Species, data = Gastropods)
hist(Gastropods.ANOVA$residuals)
plot(Gastropods.ANOVA)


Gastropods$LOGAbundance = log10(Gastropods$Abundance + 1)

Gastropods$SQRTAbundance = sqrt(Gastropods$Abundance + 1)

summary(Gastropods.ANOVA)
summary(Gastropods$SQRTAbundance.ANOVA)

interaction.plot(Gastropods$Zone, Gastropods$Species, Gastropods$Abundance, main= "Gastropod Interaction Plot", xlab = "Gastropod Zone", ylab= "Mean of Gastropod Abundance",legend = FALSE))

interaction.plot(Gastropods$Zone, Gastropods$Species, Gastropods$Abundance, main= "Gastropod Interaction Plot", xlab = "Gastropod Zone", ylab= "Mean of Gastropod Abundance", legend = FALSE)                 


TukeyHSD(Gastropods.ANOVA)
tuk<-TukeyHSD(Gastropods.ANOVA)
plot(tuk)`

正如您所看到的那样,轴非常糟糕,我想突出显示零间隔之外的重要值。

enter image description here

1 个答案:

答案 0 :(得分:14)

试试这个:

TukeyHSD(Gastropods.ANOVA)
tuk<-TukeyHSD(Gastropods.ANOVA)
psig=as.numeric(apply(tuk$`Zone:Species`[,2:3],1,prod)>=0)+1
op=par(mar=c(4.2,9,3.8,2))
plot(tuk,col=psig,yaxt="n")
for (j in 1:length(psig)){
axis(2,at=j,labels=rownames(tuk$`Zone:Species`)[length(psig)-j+1],
     las=1,cex.axis=.8,col.axis=psig[length(psig)-j+1])
}
par(op)

你会得到类似于这个情节的东西 enter image description here