29

I tried adding a subtitle using +opts(subtitle="text") but nothing showed up. The main title does work (+opts(title="text")).

I would also like to use a larger font for the axis (labels and coordinates), but I can't tell how to do that.

David B
  • 29,258
  • 50
  • 133
  • 186
  • For the first question, there is a better answer here: http://stackoverflow.com/questions/11724311/how-to-add-a-ggplot2-subtitle-with-different-size-and-colour – naught101 Aug 29 '14 at 02:51
  • Marking a question as duplicate because there is a newer question seem very odd to me. So why was this marked as duplicate? – Jaap Aug 29 '14 at 08:35

2 Answers2

46

theme_get() will show you the "hidden" options that you can use in opts(), post 0.91 it's theme()

Current:

theme(axis.text.x=element_text(size=X))
theme(axis.text.y=element_text(size=X))

Pre 0.91:

opts(axis.text.x=theme_text(size=X))
opts(axis.text.y=theme_text(size=X))

Change size, to your desired size.

wrt the title, you can use "\n" to move the remaining text to a new line:

Current:

labs(title="text \n more text")

Pre 0.91:

opts(title="text \n more text") 

ggplot2 doesn't have "subtitle" functionality. But you can use the \n term in any of the labels to drop down a line.

Brandon Bertelsen
  • 43,807
  • 34
  • 160
  • 255
  • 3
    `theme_text` is now deprecated use `element_text` instead. I would say more, but I'm searching for how to use `element_text` myself. The help is just a stub. – geneorama Sep 13 '12 at 18:14
  • Try updating your packages. The docs have been improved, and I've also updated me answer. – Brandon Bertelsen Sep 13 '12 at 18:40
8

Update: ggplot version 2.2.0 can do subtitles, as demonstrated e.g. in this blog post.

Example:

library(ggplot2)
packageVersion("ggplot2")  ## 2.2.0
d <- data.frame(x=1:5,y=1:5)
ggplot(d,aes(x,y))+
    labs(title="abc",subtitle="def")+
    ## default left-aligned: moved them to center alignment
    theme(plot.title=element_text(hjust=0.5),
          plot.subtitle=element_text(hjust=0.5))

enter image description here

Ben Bolker
  • 211,554
  • 25
  • 370
  • 453