Plot title at bottom of plot using ggplot2

前端 未结 2 1354
野性不改
野性不改 2020-12-07 01:19

In ggplot2, how to put the plot title at the bottom of the plot.

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

puts the title at middle and top

相关标签:
2条回答
  • 2020-12-07 01:50

    With the dev version you can use the caption argument,

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

    Alternatively, wrap the plot in grid.arrange(),

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

    0 讨论(0)
  • 2020-12-07 01:51

    Here is a solution using 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 讨论(0)
提交回复
热议问题