X-Axis Labels on a 45-Degree Angle using R (PART II)

Let me be the ith person to point to the exceptionally useful ggplots2 package in R. Its default plot settings (as in qplot() ) make for some particularly nice figures.

However, I bring it up now because it provides a slightly more flexible method of rotating axis labels (different from the method used here). GGplot can be a little complicated at first glance (I recommend this nice tutorial) but trust me, it is well worth the investment in time. Below is the creation of a simple histogram using qplot. Note that qplot is stored in an object and then called with “+ opts( )” to tweak the particular settings of interest. It is actually this second command which draws the plot.

> hgram <- qplot(data$test, xlab=””)
> hgram + opts(axis.text.x=theme_text(size=16, angle=40, vjust=.8, hjust=1.01))
In this example the x axis text (labels) are increased in size, tilted 40 degrees counter-clockwise and then vertically and horizontally adjusted. I’ve found this method useful in those cases where just using the “srt” argument might have failed.

One response to “X-Axis Labels on a 45-Degree Angle using R (PART II)

  1. I need an help for my rotation axis x label legend in r. My x axis labels are longer, so, I would like to rotate. I use R software version 3.1.1. and I work under R commander. I have generate my boxplot but xlab is longer.

    Please, I need your help to solve my problem.
    Best regards

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s