You can use this approach, but justification is unbelievably finicky. Because atop
was designed to format equations, it automatically centers, so you need to hack around that by inserting spaces before the longer title and playing with hjust
. There seems to be an upper limit on title size with this approach, too; there has to be space for the spaces to move off to the left.
What I managed:
library(ggplot2)
title <- paste(" An analysis of the mtcars dataset")
subheader <- paste("How does mpg change by number of cyl?")
ggplot(mtcars, aes(mpg,cyl)) +
geom_smooth(aes(fill="Mean",level=0.095)) +
ggtitle(bquote(atop(bold(.(title)), atop(.(subheader), "")))) +
scale_fill_grey(name='95% Confidence\n Interval',start=.65,end=.65) +
theme(plot.title = element_text(size = rel(1.3),hjust=-.6,face="bold"))
To go any further, you're probably going to need to break into grid.