title: Adding dynamic chart titles in ggplot2
body: <p>This follows on from my last question. I've spent an hour or so trying to work out how to pass the variable I use to filter my dataframe to the title of the graph that is generated.</p>
  
  <p>Following on from my previous questions.</p>
  
  <pre><code>library (tidyverse)
  library (epitools)
  
  
  # here's my made up data
  
  DISEASE = c("Marco Polio","Marco Polio","Marco Polio","Marco Polio","Marco Polio",
              "Mumps","Mumps","Mumps","Mumps","Mumps",
              "Chicky Pox","Chicky Pox","Chicky Pox","Chicky Pox","Chicky Pox")
  YEAR = c(2011, 2012, 2013, 2014, 2015,
           2011, 2012, 2013, 2014, 2015,
           2011, 2012, 2013, 2014, 2015)
  VALUE = c(82,89,79,51,51,
            79,91,69,89,78,
            71,69,95,61,87)
  AREA =c("A", "B","C")
  
  DATA = data.frame(DISEASE, YEAR, VALUE,AREA)
  
  DATA&lt;-
  DATA %&gt;%
    mutate(POPN = case_when(
      AREA == "A" ~ 2.5,
      AREA == "B" ~ 3,
      AREA == "C" ~ 7,
      TRUE ~ 0)) %&gt;%
    group_by(DISEASE,AREA,POPN) %&gt;%
    count(AREA) %&gt;%
    mutate(res = list(pois.byar(n, POPN))) %&gt;%
    unnest()
  
  DATA%&gt;%filter(DISEASE== "Marco Polio")%&gt;%
    ggplot(aes(x=AREA, y=rate)) +geom_point() +
    geom_hline(aes(yintercept=rate[AREA == "A"]), 
               linetype="dashed", color = "red")
  </code></pre>
  
  <p>I thought that this</p>
  
  <pre><code>    x_label = "Area!!!"
      y_label = "Rate!!!"
      DATA%&gt;%filter(DISEASE== "Marco Polio")%&gt;%
            ggplot(aes(x=AREA, y=rate)) +geom_point() +
            geom_hline(aes(yintercept=rate[AREA == "A"]), 
                       linetype="dashed", color = "red")+
  labs(x = x_label,y = y_label)+
  ggtitle(DATA$DISEASE)
  </code></pre>
  
  <p>Why doesn't it?
  It generates a chart for Marco Polio but uses Chicky Pox as the title.</p>
  
  <p>What I want is (false code)
  ggtitle == filter(disease)</p>
  
  <p>Because what I'm going to do after this is walk and purr to get every chart for every infection and I'd like to title automatically.</p>
  
  <p>Ta.</p>
  
  <p>EDIT:
  I've tried the suggestion below and it doesn't quite work.</p>
  
  <p>I've tried this</p>
  
  <pre><code>DATA%&gt;%filter(DISEASE== "Mumps")%&gt;%
    ggplot(aes(x=AREA, y=rate)) +geom_point() +
    geom_hline(aes(yintercept=rate[AREA == "A"]), 
               linetype="dashed", color = "red")+
    ggtitle(paste(DISEASE))
  
  
  DATA%&gt;%filter(DISEASE== "Mumps")%&gt;%
    ggplot(aes(x=AREA, y=rate)) +geom_point() +
    geom_hline(aes(yintercept=rate[AREA == "A"]), 
               linetype="dashed", color = "red")+
    ggtitle(as.character(DISEASE))
  </code></pre>
  
  <p>and no luck.</p>
  
  <p>Does it have something to do with DISEASE becoming a FACTOR when it gets grouped?</p>