Applying theme moves ylab

4 views
Skip to first unread message

Brandon Farr

unread,
Mar 30, 2009, 8:10:25 PM3/30/09
to ggplot2
I've noticed that applying a theme can play tricks with the position
of the y-axis label. When the following is run, the y-axis label is
centered on the y-axis initially:

qplot(mpg, wt, data = mtcars)

Then when the following is run, the y-axis label moves down,
practically off the plot:

last_plot() + theme_bw()

Any thoughts,
Brandon

-----------
> sessionInfo()
R version 2.8.1 (2008-12-22)
i386-apple-darwin8.11.1

locale:
en_US.UTF-8/en_US.UTF-8/C/C/en_US.UTF-8/en_US.UTF-8

attached base packages:
[1] grid stats graphics grDevices utils datasets
[7] methods base

other attached packages:
[1] xts_0.6-4 zoo_1.5-5 ggplot2_0.8.2 reshape_0.8.2
[5] plyr_0.1.4 proto_0.3-8

loaded via a namespace (and not attached):
[1] lattice_0.17-17

David Kahle

unread,
Mar 30, 2009, 8:16:38 PM3/30/09
to Brandon Farr, ggplot2
You can add

+ opts(axis.title.y = theme_text(size = 12, vjust = 1/2, angle = 90))

or a variant to the end of the plot, that should fix it. Hadley has
fixed it for the next release I believe.

Cheers
david.

Brandon Farr

unread,
Mar 30, 2009, 8:50:58 PM3/30/09
to ggplot2
Thanks, that works. I'm glad to hear it's been fixed for the next
release.

All the best,
Brandon
Reply all
Reply to author
Forward
0 new messages