ggplot2:如何调整绘图区域与轴文本之间的间距

3
我该如何调整(增加或减少)坐标轴文本(数字)与绘图区域(灰色区域)之间的间距?
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


这个问题可能会有所帮助:https://dev59.com/mGAg5IYBdhLWcg3w_fLV。 - xtluo
3
请将 axis.title.y 替换为 axis.text.y,以实现增加y轴上文本与标题之间的距离。原文链接请见:Increase distance between text and title on the y-axis - Henrik
是的!那似乎是正确的解决方案。 - mindlessgreen
1个回答

7
一个选项可能是使用axis.ticks.length()来设置绘图区域和轴文本之间的间距,因为您选择不显示刻度线(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())

它产生输出:

enter image description here

或者,您可以定义margin()的参数(t、r、b、l)来调整空间

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


临时解决方案!我很惊讶居然没有适当的参数来进行调整。 - mindlessgreen
1
应该有一个合适的解决方案来做这个,但我很难找到它们。希望能从其他人那里听到一些更好的解决方案! - Prradep

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接