I'm developing a custom ggplot theme which includes horizontally-rotated y-axis labels, and I want to increase the spacing between the tick labels and the axis labels. This post suggests adjusting the vjust
parameter but that isn't appropriate in this case. Alignment (e.g. left or right within the box) is different from the spacing of that box relative to the tick label.
For example with axis.title.y=element_text(angle=0, vjust=1, hjust=1))
, then I get the correct alignment but it's too close to the tick labels:
If I set hjust=2
then the text is no longer properly flushed right:
I've played with the margin
theme options but I don't think they are applicable here. Any ideas?
EDIT Here's a simple MWE for testing as requested:
df <- data.frame(x=1:10, y=1:10)
ggplot(df, aes(x,y)) +
geom_line() +
theme(axis.title.y=element_text(angle=0, vjust=1, hjust=1)) +
labs(y="This\nis a\nreally long\naxis\nlabel")