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())
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())
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:
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)))