Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Modifying a Tukey HSD 95% family-wise CL plot in Rstudio

Tags:

plot

r

rstudio

I wanted to know how I could change the axis of a plot of Tukey's HSD so I could shorten the words to make each comparison fit and not look ridiculous.

It would help a lot if you could help me with codes for changing axis labels, font size and color.

There are quite a few comparisons in the plot, so I would like to make the significant ones (the comparisons whose intervals are not on the "0" line) stand out more by changing their color.

`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)`

As you can see the axis's are terrible and I want to highlight the significant values outside of the zero interval.

enter image description here

like image 716
JoshM8 Avatar asked Dec 03 '22 16:12

JoshM8


1 Answers

Try this:

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)

You will have something similar to this plot enter image description here

like image 97
Robert Avatar answered Dec 30 '22 09:12

Robert