增加在y轴文本和标题之间的距离(Increase distance between text and

2019-07-18 14:15发布

y轴标题出现得太靠近轴文本。

ggplot(mpg, aes(cty, hwy)) + geom_point()

我试图改变许多参数与价值theme()但似乎没有任何帮助。

Answer 1:

ggplot2 2.0.0可以使用margin =的参数element_text()来改变轴标题和数字之间的距离。 设置的值margint运算, r飞行, b ottom,和l元件的EFT侧。

ggplot(mpg, aes(cty, hwy)) + geom_point()+
  theme(axis.title.y = element_text(margin = margin(t = 0, r = 20, b = 0, l = 0)))

margin ,也可用于其他element_text元素(参见?theme ),如axis.text.xaxis.text.ytitle



Answer 2:

基于此论坛的帖子: https://groups.google.com/forum/#!topic/ggplot2/mK9DR3dKIBU

听起来好像是最容易的事情就是你的x轴前加一个换行符(\ n)和你的Y轴的标签后。 似乎轻松了很多(虽然笨)比上面张贴的解决方案。

ggplot(mpg, aes(cty, hwy)) + 
    geom_point() + 
    xlab("\nYour_x_Label") + ylab("Your_y_Label\n")

希望帮助!



文章来源: Increase distance between text and title on the y-axis