使用 ggplot2 在绘图底部绘制标题

Plot title at bottom of plot using ggplot2

在ggplot2中,如何将绘图标题放在绘图的底部。

qplot(rnorm(100)) + ggtitle("My Title")

将标题放在图的中间和顶部,而我希望它位于图的中间和底部

这是一个使用 grid.text 的解决方案:

library("grid")
qplot(rnorm(100)) + theme(plot.margin=unit(c(0.5, 1, 2, 0.5), "lines"))
grid.text("My Title", x = unit(0.5, "npc"), y = unit(0, "npc"),
          vjust = -0.5, gp = gpar(cex=1.2))

对于开发版本,您可以使用标题参数,

ggplot() + 
  labs(caption="Bottom Title") + 
  theme(plot.caption = element_text(hjust=0.5, size=rel(1.2)))

或者,将绘图包裹在 grid.arrange(),

gridExtra::grid.arrange(ggplot(), bottom="Bottom Title")