2013-01-23 223 views

回答

106

ggplot2 2.0.0您可以使用margin =参数element_text()来更改轴标题和数字之间的距离。设置margin的值为t op,r ight,b ottom和l元素的后侧。

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

39

基于此论坛的帖子: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") 

希望帮助!

+0

我通常使用这种方法,它更快,它不需要添加另一个选项ggplot,除非我需要一些特定的调整。 –

相关问题