I’ve been trying to find a simpler bit of R code that will allow axis labels to be written in at an angle, and thanks to my obsessive scanning of the R-help mailing list I found a nice example (all credit to Uwe Ligges and Marc Schwartz for their approach). I’ve made a few cosmetic tweaks in moving the labels off of the x-axis and changing the labels.
The following code will produce the figure below:
labels <- c(“January”, “February”, “March”, “April”, “May”, “June”, “July”, “August”, “September”, “October”, “November”, “December”)
labels <- month.name[1:12]
mp <- barplot(1:12, axes = FALSE, axisnames = FALSE)
text(mp, par(“usr”)[3], labels = labels, srt = 45, adj = c(1.1,1.1), xpd = TRUE, cex=.9)
axis(2)

Configure to your heart’s content. I know I will.
Updated code: R has a few built in constants and I think it makes things much simpler to take advantage of them (letters, LETTERS, month.name, month.abb and pi).
Nice method used to create the month labels. I needed the ‘, srt = 45′ bit. Cheers!
Brilliant! Thanks a lot. Nothing worse than R hiding important labels when they don’t fit and the documentation being difficult to follow.
Pingback: X-Axis Labels on a 45-Degree Angle using R (PART II) « Justin Leinaweaver
Thanks! Worked a charm and will reblog.
Pingback: On An Angle « Over Exposed
Fantastic example. Thanks very much.
After much playing around, thanks to your example I came up with the following to produce text going the other way. It involves only three changes, but I think it seems rather like a hack than a solution. Any suggestions?
labels <- month.name[1:12]
mp <- barplot(1:12, axes = FALSE, axisnames = FALSE)
text(mp, par("usr")[3]-.5, labels = labels, srt = 315, adj = c(0,0), xpd = TRUE, cex=.9)
axis(2)
sessionInfo() =
R version 2.13.1 (2011-07-08)
Platform: x86_64-pc-mingw32/x64 (64-bit)
Thanks again,
Cheers,
Davy
Hi Davy,
Yeah, all of this feels somehow unsatisfying. A bit too klugey. As you’ve shown, par(“usr”) defines a vector (of length 4) to specify the plotting region. The third element refers to ‘y1′ so by subtracting from it you can adjust the label’s placement.
Other than switching to ggplot (and learning that whole other set of commands) I think we’re stuck with playing with ‘adj’ once the plot is otherwise finished.