title: ggplot2: Creating themed title, subtitle with cowplot
body: <p>I have a list of data frames that I use to make a list of <code>ggplot</code>s, and then assemble into a grid of plots with <code>cowplot</code>. I need to then attach a shared title, subtitle, and caption. I want to do this in a way that these labels will have the same theme elements (size, fontface, etc) as if they were created by <code>labs</code> instead of <code>cowplot::draw_label</code>.</p>
  
  <p>In my real situation, I have several choropleths that each have their own units and scales, which is why I can't just facet, but instead need to build the plots independent of one another.</p>
  
  <p>Here's a simplified version of the data, and the packages I have loaded:</p>
  
  
  
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  library(cowplot)
  
  dfs &lt;- list(
    adults_no_diploma = structure(list(
      tract = c("09003405100", "09003405200", "09003405300", "09003405401", "09003405402", "09003405500", "09003405600", "09003405700", "09003405800", "09003405900"), 
      value = c(0.08, 0.108, 0.095, 0.099, 0.105, 0.103, 0.161, 0.279, 0.056, 0.055)), 
      row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame")), 
    severe_cost_burden = structure(list(
      tract = c("09003405100", "09003405200", "09003405300", "09003405401", "09003405402", "09003405500", "09003405600", "09003405700", "09003405800", "09003405900"), 
      value = c(0.128, 0.147, 0.165, 0.1, 0.151, 0.11, 0.179, 0.184, 0.14, 0.038)), 
      row.names = c(NA, -10L), class = c("tbl_df", "tbl", "data.frame"))
  )
  </code></pre>
  
  <p>I'm working with a custom theme (again, a simplified version):</p>
  
  <pre class="lang-r prettyprint-override"><code>theme_georgia &lt;- function(...) {
    theme_gray(base_family = "Georgia", ...) + 
      theme(plot.title = element_text(face = "bold"))
  }
  
  plots &lt;- dfs %&gt;%
    imap(~{
      ggplot(.x, aes(x = value)) + 
        geom_density() + 
        ggtitle(.y) +
        theme_georgia()
      })
  
  gridded &lt;- plot_grid(plotlist = plots, nrow = 1)
  </code></pre>
  
  <p>Following the <a href="https://cran.r-project.org/web/packages/cowplot/vignettes/plot_annotations.html" rel="noreferrer"><code>cowplot</code> annotations vignette</a>, I can make a title with <code>ggdraw() + draw_label("Socio-economic measures")</code> and manually set things like font size, but what I'd prefer is to somehow define that label <em>as</em> a title; that is, the theme would apply everything in <code>plot.title</code> to it, and the same for creating a subtitle and caption.</p>
  
  <p>My current workaround is to make an empty <code>ggplot</code> with <code>labs</code> for the title and subtitle, do the same for a caption, and stack them vertically with <code>cowplot::plot_grid</code>.</p>
  
  <pre class="lang-r prettyprint-override"><code>title_gg &lt;- ggplot() + 
    labs(title = "Socio-economic measures", subtitle = "By census tract, 2016") + 
    theme_georgia()
  plot_grid(title_gg, gridded, ncol = 1, rel_heights = c(0.15, 1))
  </code></pre>
  
  <p><img src="https://i.imgur.com/ta5imRV.png" alt=""></p>
  
  <p>The workaround is okay, but I like the neatness and alignment you get with <code>draw_label</code>. I could instead add in these theme elements one by one to mimic a title:</p>
  
  <pre class="lang-r prettyprint-override"><code>title_theme &lt;- ggdraw() +
    draw_label("Socio-economic measures", 
               fontfamily = theme_georgia()$text$family, 
               fontface = theme_georgia()$plot.title$face, x = 0.05, hjust = 0)
  plot_grid(title_theme, gridded, ncol = 1, rel_heights = c(0.2, 1))
  </code></pre>
  
  <p><img src="https://i.imgur.com/zudrOV0.png" alt=""></p>
  
  <p>My question is whether there's any way I might combine these approaches to pull all the relevant theme elements and feed them to <code>draw_label</code> quickly, or somehow tell <code>draw_label</code> that this thing is a title and should get title theme elements, and this other thing is a subtitle, and so on. I imagine some sort of magic like this:</p>
  
  <pre class="lang-r prettyprint-override"><code>ggdraw() + 
    draw_label("Socio-economic measures", theme_georgia()$plot.title_elements)
  </code></pre>
  
  <p>or:</p>
  
  <pre class="lang-r prettyprint-override"><code>ggdraw() + 
    draw_label("Socio-economic measures", type = "title") + theme_georgia()
  </code></pre>