d.putto
d.putto

Reputation: 7565

Plot title at bottom of plot using ggplot2

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 of plot, while I want it to be at middle and bottom of the plot.

Upvotes: 16

Views: 16743

Answers (2)

baptiste
baptiste

Reputation: 77096

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

enter image description here

Upvotes: 14

rcs
rcs

Reputation: 68819

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

Upvotes: 13

Related Questions