如何在ggplot2中重新定位轴标题?

时间:2017-04-11 17:50:32

标签: r ggplot2

我想重新定位(例如,向上移动10px)此图表的x轴标签

  ggplot() + geom_bar(aes(x=carb, y=..count..),data=mtcars)

我认为我可以使用vjust,但正如github issue中所述,垂直移动x标签的唯一方法是使用margin

theme(axis.text.x = element_text(margin=margin(0,0,-10,0)))

然而,边缘产生的东西与x-title的简单重新定位非常不同,因为它也会调整图表的大小。我可以简单地移动x标签吗?

1 个答案:

答案 0 :(得分:0)

你可以这样做

 ggplot() + geom_bar(aes(x=carb, y=..count..),data=mtcars)+ 
    theme(axis.title.x=element_text(margin=margin(-5,0,0,0)))

只需更改数字,直到获得满意的结果。