How to change spacing between axis label and ticks labels with ggplot2?

ClementWalter picture ClementWalter · Jun 8, 2016 · Viewed 9.4k times · Source

This seems a very basic question but I can't find the answer: how to change the default spacing between the axis main label and the axis ticks label? I have looked through theme documentation but could find only the axis.ticks.margin option which lets set the spacing between ticks and ticks label.

For example,

df <- data.frame(x = 1:5, y = seq(from=1, l = 5))
ggplot(df, aes(x,y)) + geom_line()

produces the following:

example

where I'd like to add more space between the label y and the axis (y and 3 are too close for me).

Answer

Tomas H picture Tomas H · Jun 8, 2016

You can try this as well

df <- data.frame(x = 1:5, y = seq(from=1, l = 5))
ggplot(df, aes(x,y)) + geom_line()+
    ylab("y\n\n")