title: ggplot2: add line for average per group (Error: No stat called StatHline.)
body: <p>I recently updated <code>ggplot2</code> package and running into major issues drawing horizontal lines for averages per group using <code>facets</code>. 
  I believe <a href="https://stackoverflow.com/questions/4244157/ggplot2-add-line-for-average-per-group">this</a> post is no longer valid?</p>
  
  <p>I am creating a time series graph using the following code:</p>
  
  <pre><code>ggplot(p2p_dt_SKILL_A,aes(x=Date,y=Prod_DL)) +
      geom_line(aes(colour="red"),lwd=1.3) +
      geom_smooth() +
      geom_line(stat = "hline", yintercept = "mean")+
      scale_x_date(labels=date_format("%b-%y"),breaks ="2 month")+
      geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-09-18"]))+
  
       geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-10-02"]))+
       geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-10-23"]))+
      ylab("DL Prod for All Skills")+
      ggtitle("BVG1 DL Prod for All Skills 2014-2015")+
      theme(axis.title.y = element_text(size = 15,face="bold",color="red"),
            plot.title = element_text(size = 15,lineheight = .8,face="bold",color="red"),
            axis.title.x = element_blank(),
            legend.position="none")+
      facet_wrap(~Patch)
  </code></pre>
  
  <p>The number 1 issue is that I can no longer use the <code>stat = "hline"</code> in the <code>geom_line(stat = "hline", yintercept = "mean")</code> because it gives the following error: <code>Error: No stat called StatHline</code>.
  so therefore I changed it to:</p>
  
  <pre><code>ggplot(p2p_dt_SKILL_A,aes(x=Date,y=Prod_DL)) +
      geom_line(aes(colour="red"),lwd=1.3) +
      geom_smooth() +
      geom_hline(yintercept = mean(p2p_dt_SKILL_A$Prod_DL))+
      scale_x_date(labels=date_format("%b-%y"),date_breaks ="2 month")+
      geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-09-18"]))+
  
       geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-10-02"]))+
       geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-10-23"]))+
      ylab("DL Prod for All Skills")+
      ggtitle("BVG1 DL Prod for All Skills 2014-2015")+
      theme(axis.title.y = element_text(size = 15,face="bold",color="red"),
            plot.title = element_text(size = 15,lineheight = .8,face="bold",color="red"),
            axis.title.x = element_blank(),
            legend.position="none")+
      facet_wrap(~Patch)
  </code></pre>
  
  <p>But this doesn't draw the horizontal line at means per Patch. It just takes the overall mean for <code>Prod_DL</code>
  See below:
  <a href="https://i.stack.imgur.com/YfIZ2.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/YfIZ2.png" alt="enter image description here"></a></p>
  
  <p>Are there any new ways now to calculate mean per group and draw horizontal lines?</p>
  
  <p>Thanks</p>
  
  <p><strong>UPDATE</strong></p>
  
  <p>Here is what I did:</p>
  
  <pre><code>#first create a dataframe which holds patch and mean values for prod dl, this will then be used in geom_hline()
  mean_Prod_DL &lt;- p2p_dt_SKILL_A%&gt;%
                                  group_by(Patch)%&gt;%
                                  summarise(mean_Prod_DL_per_patch = mean(Prod_DL))
  
  
  ggplot(p2p_dt_SKILL_A,aes(x=Date,y=Prod_DL)) +
          scale_x_date(labels=date_format("%b-%y"),date_breaks ="2 months")+
          geom_line(aes(colour="red"),lwd=1.3) +
          geom_smooth() +
          geom_hline(data = mean_Prod_DL,aes(yintercept = mean_Prod_DL_per_patch),lty=2)+
          geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-09-18"]))+
           geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-10-02"]))+
           geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-10-23"]))+
          geom_vline(xintercept = as.numeric(p2p_dt_SKILL_A$Date[p2p_dt_SKILL_A$Date=="2015-12-04"]))+
          ylab("DL Prod for All Skills")+
          ggtitle("BVG1 DL Prod for All Skills 2014-2016")+
          theme(axis.title.y = element_text(size = 15,face="bold",color="red"),
                plot.title = element_text(size = 15,lineheight = .8,face="bold",color="red"),
                axis.title.x = element_blank(),
                legend.position="none")+
          facet_wrap(~Patch)
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/WQAoA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/WQAoA.png" alt="enter image description here"></a></p>