You should use function bquote()
instead of expression()
to use titles that are stored as variables. And variable names should be placed inside .()
plot.title = 'TITLE'
plot.subtitle = 'SUBTITLE'
ggplot(mtcars,aes(disp,mpg))+geom_point()+
ggtitle(bquote(atop(.(plot.title), atop(italic(.(plot.subtitle)), ""))))
UPDATE - ggplot2 version 2.2.1
The latest ggplot2 version now can produce subtitles directly, so you don't have to use bquote()
and expression()
. The result is atchieved with argument subtitle =
of function labs()
.
ggplot(mtcars,aes(disp,mpg))+geom_point()+
labs(title = plot.title,subtitle = plot.subtitle) +
theme(plot.subtitle = element_text(face = "italic"))
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…