title: ggplot: Subset a layer where data is passed using a pipe
body: <p>I am trying to subset a layer of a plot where I am passing the data to <code>ggplot</code> through a pipe. </p>
  
  <p>Here is an example: </p>
  
  <pre><code>library(dplyr)
  library(ggplot2)
  library(scales)
  
  set.seed(12345)
  df_example = data_frame(Month = rep(seq.Date(as.Date("2015-01-01"),
                                               as.Date("2015-12-31"), by = "month"), 2),
                          Value = sample(seq.int(30, 150), size = 24, replace = TRUE),
                          Indicator = as.factor(rep(c(1, 2), each = 12)))
  
  df_example %&gt;% 
    group_by(Month) %&gt;% 
    mutate(`Relative Value` = Value/sum(Value)) %&gt;% 
    ungroup() %&gt;% 
    ggplot(aes(x = Month, y = Value, fill = Indicator, group = Indicator)) + 
    geom_bar(position = "fill", stat = "identity") + 
    theme_bw()+ 
    scale_y_continuous(labels = percent_format()) + 
    geom_line(aes(x = Month, y = `Relative Value`))
  </code></pre>
  
  <p>This gives: </p>
  
  <p><a href="https://i.stack.imgur.com/SiyUf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/SiyUf.png" alt="enter image description here"></a></p>
  
  <p>I would like only one of those lines to appear, which I would be able to do if something like this worked in the <code>geom_line</code> layer: </p>
  
  <pre><code>  geom_line(subset = .(Indicator == 1), aes(x = Month, y = `Relative Value`))
  </code></pre>
  
  <h2>Edit:</h2>
  
  <p>Session info: </p>
  
  <blockquote>
    <p>R version 3.2.1 (2015-06-18) Platform: x86_64-w64-mingw32/x64 (64-bit) Running under: Windows Server 2012 x64
    (build 9200)</p>
    
    <p>locale: <a href="https://i.stack.imgur.com/h318F.png" rel="nofollow noreferrer">2</a> LC_COLLATE=English_United States.1252 
    LC_CTYPE=English_United States.1252    [3] LC_MONETARY=English_United
    States.1252 LC_NUMERIC=C                           [5]
    LC_TIME=English_United States.1252    </p>
    
    <p>attached base packages: <a href="https://i.stack.imgur.com/h318F.png" rel="nofollow noreferrer">2</a> stats     graphics  grDevices utils<br>
    datasets  methods   base     </p>
    
    <p>other attached packages:  <a href="https://i.stack.imgur.com/h318F.png" rel="nofollow noreferrer">2</a> scales_0.3.0    lubridate_1.3.3
    ggplot2_1.0.1   lazyeval_0.1.10 dplyr_0.4.3     RSQLite_1.0.0<br>
    readr_0.2.2      [8] RJDBC_0.2-5     DBI_0.3.1       rJava_0.9-7    </p>
    
    <p>loaded via a namespace (and not attached):  <a href="https://i.stack.imgur.com/h318F.png" rel="nofollow noreferrer">2</a> Rcpp_0.12.2<br>
    knitr_1.11       magrittr_1.5     MASS_7.3-40      munsell_0.4.2<br>
    lattice_0.20-31   [7] colorspace_1.2-6 R6_2.1.1         stringr_1.0.0 
    plyr_1.8.3       tools_3.2.1      parallel_3.2.1   [13] grid_3.2.1<br>
    gtable_0.1.2     htmltools_0.2.6  yaml_2.1.13      assertthat_0.1<br>
    digest_0.6.8     [19] reshape2_1.4.1   memoise_0.2.1<br>
    rmarkdown_0.8.1  labeling_0.3     stringi_1.0-1    zoo_1.7-12<br>
    [25] proto_0.3-10</p>
  </blockquote>