3

How do I adjust (increase or decrease) space between the axis text (numbers) and the plot area (grey area)?

dfr <- data.frame(x=1:5,y=1:5)
ggplot(dfr,aes(x,y))+
  geom_point()+
  theme(axis.title=element_blank(),
        axis.ticks=element_blank())

fig

mindlessgreen
  • 11,059
  • 16
  • 68
  • 113
  • [This question](https://stackoverflow.com/questions/22945651/how-to-remove-space-between-axis-area-plot-in-ggplot2) might be helpful. – xtluo Jul 15 '17 at 09:35
  • 3
    See [Increase distance between text and title on the y-axis](https://stackoverflow.com/questions/14487188/increase-distance-between-text-and-title-on-the-y-axis). Just replace `axis.title.y` with `axis.text.y`. – Henrik Jul 15 '17 at 11:17
  • Yep! That seems to be the right solution. – mindlessgreen Jul 15 '17 at 11:39

1 Answers1

7

One option could be using the axis.ticks.length() for setting the space between the plot area and axis text, as you have chosen not to display the ticks (axis.ticks=element_blank()).

ggplot(dfr,aes(x,y))+
  geom_point()+
    theme(axis.title=element_blank(),
          axis.ticks.length = unit(.85, "cm"),
          axis.ticks=element_blank())

It produces the output:

enter image description here

Alternatively, you can define the parameters(t,r,b,l) of the margin() to adjust the space.

ggplot(dfr,aes(x,y))+
  geom_point()+
  theme(axis.title=element_blank(),
        axis.ticks=element_blank(),
        axis.text.x=element_text(margin = margin(t = 20)),
        axis.text.y=element_text(margin = margin(r = 20)))

enter image description here

Prradep
  • 5,506
  • 5
  • 43
  • 84