title: Creating a line graph (mean), arranged by facets, with standard error of mean error bars: ggplot
body: <p>Hi Stack Overflow community,</p>
  
  <p>I have a dataset:</p>
  
  <pre><code>conc branch  length stage factor
  1    1000      3   573.5   e14   NRG4
  2    1000      7   425.5   e14   NRG4
  3608 1000     44  5032.0   P10   NRG4
  3609 1000      0     0.0   P10   NRG4
  </code></pre>
  
  <p>FYI</p>
  
  <pre><code>&gt; str(dframe1)
  'data.frame':   3940 obs. of  5 variables:
  $ conc  : Factor w/ 6 levels "0","1","10","100",..: 6 6 6 6 6 6 6 6 6 6 ...
  $ branch: int  3 7 5 0 1 0 0 4 1 1 ...
  $ length: num  574 426 204 0 481 ...
  $ stage : Factor w/ 8 levels "e14","e16","e18",..: 1 1 1 1 1 1 1 1 1 1 ...
  $ factor: Factor w/ 2 levels "","NRG4": 2 2 2 2 2 2 2 2 2 2 ...
  </code></pre>
  
  <p>I would like to create facetted line graphs, plotting the mean +/- standard error of the mean</p>
  
  <p>I have tried experimenting and building a ggplot from others (here and on the web). </p>
  
  <p>I have successfully used scripts that will make bargraphs this way:</p>
  
  <pre><code>errbar.ggplot.facets &lt;- ggplot(dframe1, aes(x = conc, y = length))
  
  ### function to calculate the standard error of the mean
  se &lt;- function(x) sd(x)/sqrt(length(x))
  
  ### function to be applied to each panel/facet
  my.fun &lt;- function(x) {
    data.frame(ymin = mean(x) - se(x), 
           ymax = mean(x) + se(x), 
           y = mean(x))}
  
  g.err.f &lt;- errbar.ggplot.facets + 
    stat_summary(fun.y = mean, geom = "bar", 
             fill = clrs.hcl(48)) + 
    stat_summary(fun.data = my.fun, geom = "linerange") + 
    facet_wrap(~ stage) +
    theme_bw()
  
  print(g.err.f)
  </code></pre>
  
  <p>Source: <a href="http://teachpress.environmentalinformatics-marburg.de/2013/07/creating-publication-quality-graphs-in-r-7/" rel="nofollow">http://teachpress.environmentalinformatics-marburg.de/2013/07/creating-publication-quality-graphs-in-r-7/</a></p>
  
  <p>In fact, I have created facetted line graphs with this script:</p>
  
  <pre><code> `ggplot(data=dframe1, aes(x=conc, y = length, group = stage)) + 
    geom_line() + facet_wrap(~stage)`
  </code></pre>
  
  <p>image:  postimg.org/image/ebpdc0sb7</p>
  
  <p>However, I used a transformed dataset of only means, SEM in another column, but I don't know how to add them.</p>
  
  <p>Given the complexity (for me) of the bargraphs + error line scripts above, I have not yet been able to integrate/synthesize these into something I need.</p>
  
  <p>In this case, the colour is not important to have. </p>
  
  <p>P.S. I apologise for the long thread (and perhaps the overkill on some details). This is my first online R question, so not sure of correct etiquette. Thank you all in advance for being so helpful!</p>
  
  <p>Darian</p>