[R] 45 Degree labels on barplot? Help understanding code previously posted.
Jim Lemon
jim at bitwrit.com.au
Sat Dec 11 10:51:02 CET 2010
On 12/11/2010 02:25 AM, Simon Kiss wrote:
> Dear colleagues,
> i found a line or two of code in the help archives from Uwe Ligges about creating slanted x-labels for a barplot and it works well for my purposes (code below). However, I was hoping someone could explain to me precisely what the code is doing.
> I'm aware it's invoking the text command, and I know the first ttwo arguments to text are x and y co-ordinates. I'm also aware that par("usr")[3] is grabbing the third element of the vector of plotting co-ordinates. But I tried replacing par("usr")[3] with just "0" and that didn't work; all the labels got bunched up on the left. Is it necessary to create a new object via "barplot" and then quote that in the x,y coordinates of text?
> Like I said, the code works great, but I'm trying to actually understand the rationale behind the elements so I can apply it in future.
Hi Simon,
The staxlab function will add an axis to an existing plot with either
staggered or rotated labels. It is somewhat similar to Uwe's function.
Looking at both the code and the examples on the help page might give
you some idea why the function was written. It is principally to allow
the user to add more labels than would be displayed on the default axes,
and to decide whether staggering or rotating those labels will produce a
better looking plot. The problem most often mentioned in adding custom
labels to a plot produced by barplot is that the bars are centered on
non-integer values, and so the user must get the return value of barplot
and use that for the axis label positions.
Jim
More information about the R-help
mailing list