title: Illustrate mean and standard deviation in ggplot2 density plot
body: <p>I'm trying to construct a plot where I plot normally distributed variables showing their mean on the x-axis and the standard deviation (SD) on the y-axis. Kinda like a density plot, but instead of having the density on the y-axis I want to have the SD (value).</p>
  
  <p>I'm working with the data below,</p>
  
  <pre><code>set.seed(1)
  mu1 &lt;- rnorm(10^5, mean = 1, sd = 1)
  mu3 &lt;- rnorm(10^5, mean = 3, sd = 2)
  </code></pre>
  
  <p>two normally distributed variables. Here their mean and sd, </p>
  
  <pre><code># install.packages("tidyverse", dependencies = TRUE)
  require(tidyverse)
  tibble(mu1, mu3) %&gt;% summarise_all(funs(mean, sd))
  #&gt; # A tibble: 1 x 4
  #&gt;    mu1_mean mu3_mean    mu1_sd   mu3_sd
  #&gt;       &lt;dbl&gt;    &lt;dbl&gt;     &lt;dbl&gt;    &lt;dbl&gt;
  #&gt; 1 0.9993454 3.000825 0.9982848 1.998234
  </code></pre>
  
  <p>I've played around with <a href="/questions/tagged/ggplot2" class="post-tag" title="show questions tagged &#39;ggplot2&#39;" rel="tag">ggplot2</a>, and other <a href="/questions/tagged/tidyverse" class="post-tag" title="show questions tagged &#39;tidyverse&#39;" rel="tag">tidyverse</a> packages, to get closer to what I want. I've also tried copying <a href="http://statistic-on-air.blogspot.com/2014/02/boxplot-with-mean-and-standard.html" rel="nofollow noreferrer">this function</a> from a box-plot doing something similar, having succeeded yet.</p>
  
  <p>Here is my start,</p>
  
  <pre><code>tibble(mu1, mu3) %&gt;% gather() %&gt;% ggplot() + 
    geom_density(aes(x = value, colour = key)) + 
    labs(x = 'mean', y = 'currently density, but I would like sd')
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/wFnWH.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wFnWH.png" alt="plot"></a></p>