Rotating X-Axis Labels in Faceted ggplot2

1,118 views
Skip to first unread message

Dave

unread,
Apr 3, 2012, 6:33:50 PM4/3/12
to ggplot2
I hope this is a simple question but unfortunately I've spent quite a
bit of time reading through the ggplot2 documentation and the ggplot2
book with no success. I want to rotate the x-axis label to a
perpendicular position as opposed to the default horizontal label
angle. Here's the snippet of code that creates the graph.

ggplot(byr, # data set name is 'byr'
aes(Date, Count, color=PH)) + # values for horizontal and vertical
axes
geom_point() + # scatter plot
geom_smooth(method=lm) + # regression line
facet_wrap(~Unit)+ # separately plot each subject by his unique
identifier
scale_x_date(major="1 week",format = "%d/%m")

I want the x-axis (i.e., Date) to display perpendicular to the axis in
a similar fashion to using the par(las=2) for the standard plot
options. It would be wonderful if I could angle the display of the
labels. Given the default horizontal display, the Dates overlap too
much to make anything recognizable even using the shorter format.
What am I missing? Thanks!

Andrew

unread,
Apr 3, 2012, 9:07:57 PM4/3/12
to ggp...@googlegroups.com
Checkout the github wiki: https://github.com/hadley/ggplot2/wiki/Axis-Attributes.

A more exhaustive list is here: https://github.com/hadley/ggplot2/wiki/+opts()-List

For ninety degree rotation, all you need to do is append:
    +opts(axis.text.x = theme_text(angle = 90))

to the end of your code, and that should do what you need.
Reply all
Reply to author
Forward
0 new messages