Move y-axis title to top of axis

31 views
Skip to first unread message

Thiago V. dos Santos

unread,
Jul 1, 2015, 4:48:02 AM7/1/15
to Ggplot2 Mailing List
Hi everyone,

I am trying to put the title of the y-axis at the top of the axis, but for some reason it always goes out of the margins. Is there any way to correct this? Please see the example below:


require(ggplot2)

xy = data.frame(x=1:10, y=10:1)

ggplot(data = xy) +
geom_point(aes(x = x, y = y)) +
labs(x='DOY', y=expression(paste("Biomass (Kg ", ha^-1,')', sep=''))) +
theme(axis.title.y = element_text(angle = 0, vjust = 1.0, hjust = 10))
'vjust=1.0' is my limit. If I try 'vjust=1.1', the title goes all the way up and no longer appears on the graphic. What am I doing wrong?

Thanks in advance,
Thiago.

--
Thiago V. dos Santos
PhD student
Land and Atmospheric Science
University of Minnesota
http://www.laas.umn.edu/CurrentStudents/MeettheStudents/ThiagodosSantos/index.htm
Phone: (612) 323 9898

Brandon Hurr

unread,
Jul 1, 2015, 2:35:49 PM7/1/15
to Thiago V. dos Santos, Ggplot2 Mailing List
I've never really understood the relationship between the values for hjust and vjust above or below 1/-1. But if you play with smaller iterations you can get closer to what you want. 

It might look nicer to use Grid and create the axis title that way you don't get the blank area to the left due to it trying to clip the image appropriately. 

ggplot(data = xy) +
geom_point(aes(x = x, y = y)) +
labs(x='DOY', y=expression(paste("Biomass (Kg ", ha^-1,')', sep=''))) +
theme(axis.title.y = element_text(angle = 0, vjust = 1.025, hjust = 10))


--
--
You received this message because you are subscribed to the ggplot2 mailing list.
Please provide a reproducible example: https://github.com/hadley/devtools/wiki/Reproducibility

To post: email ggp...@googlegroups.com
To unsubscribe: email ggplot2+u...@googlegroups.com
More options: http://groups.google.com/group/ggplot2

---
You received this message because you are subscribed to the Google Groups "ggplot2" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ggplot2+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages