【问题标题】:ggplot2: How to adjust spacing between plot area and axis text [duplicate]ggplot2:如何调整绘图区域和轴文本之间的间距[重复]
【发布时间】:2017-07-15 09:27:04
【问题描述】:

如何调整(增加或减少)轴文本(数字)和绘图区域(灰色区域)之间的间距?

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

【问题讨论】:

标签: r ggplot2


【解决方案1】:

一个选项可能是使用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())

它产生输出:

或者,您可以将margin() 的参数(t,r,b,l) 定义为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)))

【讨论】:

  • 黑客解决方案!我很惊讶没有适当的论据来调整它。
  • 应该有一个适当的解决方案来做到这一点,但我无法轻易找到它们。希望从其他人那里听到一些其他更好的解决方案!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-09-02
相关资源
最近更新 更多