4

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

5
  • 2
    Can you post a link to the image you want?
    – Barett
    Commented May 30, 2015 at 16:14
  • 2
    providing what you already tried/got might be a good idea. It could also be helpful to split your question into multiple questions, one for each task/problem your are currently facing. Commented May 30, 2015 at 16:14
  • 2
    Welcome to SO! Please do provide a working example (see stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example ) so that we can know exactly what you are trying to do. If you can upload the image somewhere and post the link someone with enough privileges can include it in the question for you.
    – nico
    Commented May 30, 2015 at 17:07
  • People will continue to downvote until you put a minimal example of your code, data and show(or explain) to us what you're trying to do. Napkin drawings are totally acceptable here. Commented May 30, 2015 at 18:27
  • 1
    I upvoted your post after I edited it, so that you'll get more viewers. I wrote posts like you did when I first got here, then I realized that the idea is to make more of a concise, less personal question. This is because SO is not like a discussion forum (at least, not this part of SO) but rather more of a quick reference resource for people running into problems during coding. The less they have to read to understand your question and its solution the better. Cheers!
    – Hack-R
    Commented Jun 1, 2015 at 11:34

1 Answer 1

17

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

5
  • Hi Robert. That looks fantastic, exactly what I wanted. However, I've come across one issue. When I insert the code you provided into R some of my axis labels are cut off. You can see that in my Gyazo here. gyazo.com/971e70712dbced9dd9444afa702a86c4 Any suggestions how to fix this?
    – JoshM8
    Commented Jun 1, 2015 at 1:58
  • 2
    Seems like you did not change the margins with par(mar=c(4.2,9,3.8,2)). If you did already try to increase the 9 to 9.5 or more.
    – Robert
    Commented Jun 1, 2015 at 2:05
  • That worked. Thank you again. I posted another (separate) question just a moment ago if you feel like indulging! Also, I would like to up vote you but it seems like that is not allowed for beginners. If there is another form of upvoting allowed please tell and I will reward you.
    – JoshM8
    Commented Jun 1, 2015 at 7:53
  • Thank you @Hack-R, and for your comments above. This is all very new to me. I'm satisfied with the help I got here so is there a way to close the thread so people don't get misguided? Perhaps you could raise awareness for my two other question on this site haha!
    – JoshM8
    Commented Jun 1, 2015 at 12:29
  • @JoshM8 You're very welcome. To effectively close the thread, just mark Robert's answer as the solution by clicking the checkmark.
    – Hack-R
    Commented Jun 1, 2015 at 15:26

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.