2015-05-04 83 views

回答

10

下面是一个解决方案使用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)) 

plot

+0

它的作品,但当我试图保存为PDF格式(使用ggsave)我没有看到标题! –

+0

你必须直接打开/关闭设备:'pdf(“file.pdf”);打印(qplot(...)); grid.text(...); dev.off()' – rcs

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

enter image description here