title: Dodge two different geoms apart in ggplot2
body: <p>Let's say I have two different sources of data. One is of repeated observations, and one is just a mean +/- standard error predicted by a model.</p>
  <pre><code>n &lt;- 30
  obs &lt;- data.frame(
    group = rep(c(&quot;A&quot;, &quot;B&quot;), each = n*3),
    level = rep(rep(c(&quot;low&quot;, &quot;med&quot;, &quot;high&quot;), each = n), 2),
    yval = c(
      rnorm(n, 30), rnorm(n, 50), rnorm(n, 90),
      rnorm(n, 40), rnorm(n, 55), rnorm(n, 70)
    )
  ) %&gt;%
    mutate(level = factor(level, levels = c(&quot;low&quot;, &quot;med&quot;, &quot;high&quot;)))
  
  model_preds &lt;- data.frame(
    group = c(&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;),
    level = rep(c(&quot;low&quot;, &quot;med&quot;, &quot;high&quot;), 2),
    mean = c(32,56,87,42,51,74),
    sem = runif(6, min = 2, max = 5)
  )
  
  </code></pre>
  <p>now I can plot these on the same graph easily enough</p>
  <pre><code>p &lt;- ggplot(obs, aes(x = level, y = yval, fill = group)) +
    geom_boxplot() +
    geom_point(data = model_preds, aes(x = level, y = mean), size = 2, colour = &quot;forestgreen&quot;) +
    geom_errorbar(data = model_preds, aes(x = level, y = mean, ymax = mean + sem, ymin = mean - sem), colour = &quot;forestgreen&quot;, size = 1) +
    facet_wrap(~group)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/SXyTu.png" rel="noreferrer"><img src="https://i.stack.imgur.com/SXyTu.png" alt="enter image description here" /></a></p>
  <p>and use that the visually look at the difference between the model predictions and the observed results.</p>
  <p>But I think this looks a bit ugly, so ideally would want to 'dodge' the point-and-errorbars geom(s) from the boxplot geom.</p>
  <p>If you'll forgive my quick paint drawing, something like this:
  <a href="https://i.stack.imgur.com/BY7Oa.png" rel="noreferrer"><img src="https://i.stack.imgur.com/BY7Oa.png" alt="enter image description here" /></a></p>
  <p>It seems like <a href="https://ggplot2.tidyverse.org/reference/position_dodge.html" rel="noreferrer">position_dodge()</a> might be the way to go but I haven't figured out how to combine two different geoms this way and the docs don't have any examples.</p>
  <p>Might be that it's impossible, but thought I'd ask to check</p>