I'm drawing a plot with ggplot2 in R and I'd like the title for the y axis to appear in the top left corner of the plot. Consider the following code for the default behaviour:
require(ggplot2)
xy = data.frame(x=1:10, y=10:1)
ggplot(data = xy) +
geom_point(aes(x = x, y = y)) +
ylab("very long label")
This produces the following graph:
I would like to move and rotate the text "very long label". I can do this somewhat using the theme()
function:
ggplot(data = xy) +
geom_point(aes(x = x, y = y)) +
ylab("very long label") +
theme(axis.title.y = element_text(angle = 0, vjust = 1.1, hjust = 10))
Which gives me this:
You can see where I'm going with this, but the margins are incorrect -- the left margin is too large because the space is reserved for a rotated label and the top margin is too small for the text.
How can I tell ggplot that I want the y axis title at that position without rotation and have it reserve the appropriate space for it?