[R] Rotating x-axis categorical labels
Marc Schwartz
marc_schwartz at me.com
Fri May 15 19:32:02 CEST 2009
On May 15, 2009, at 12:18 PM, Bill Hudspeth wrote:
> Hello,
>
> I am using barplot to generate a histogram of population by county. I
> need to plot the bars for about 35 counties, and would like to rotate
> the county name labels on the x-axis to a vertical orientation so
> that I
> can fit them all. An example of my syntax is below:
>
> r.barplot(x,main=main,
> xlab
> =
> xlab
> ,ylab
> =
> ylab
> ,names_arg
> =
> counties
> ,axis_lty
> =
> 1
> ,col
> ="lavender",ylim=r.c(0,100),cex_axis=0.7,cex_names=0.7,offset=0,las=1)
>
> Using "las" rotates the y-axis labels --- how do I rotate the X-axis
> labels...?
>
> Thanks, William
par("las") takes 4 values 0:3. See ?par
Try:
# Rotate both x and y
barplot(1:5, names.arg = paste("Bar", 1:5), las = 2)
# Rotate just x
barplot(1:5, names.arg = paste("Bar", 1:5), las = 3)
If you want something other than a 90 degree rotation, see:
http://cran.r-project.org/doc/FAQ/R-FAQ.html#How-can-I-create-rotated-axis-labels_003f
HTH,
Marc Schwartz
More information about the R-help
mailing list