title: R, ggplot, How do I keep related points together when using jitter?
body: <p>One of the variables in my data frame is a factor denoting whether an amount was gained or spent.  Every event has a &quot;gain&quot; value; there may or may not be a corresponding &quot;spend&quot; amount.  Here is an image with the observations overplotted:
  <a href="https://i.stack.imgur.com/t412M.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/t412M.png" alt="enter image description here" /></a></p>
  <p>Adding some random jitter helps visually, however, the &quot;spend&quot; amounts are divorced from their corresponding gain events:</p>
  <p><a href="https://i.stack.imgur.com/2i0Xl.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/2i0Xl.png" alt="enter image description here" /></a></p>
  <p>I'd like to see the blue circles &quot;bullseyed&quot; in their gain circles (where the &quot;id&quot; are equal), and jittered as a pair.  Here are some sample data (three days) and code:</p>
  <pre><code>library(ggplot2)
  ccode&lt;-c(Gain=&quot;darkseagreen&quot;,Spend=&quot;darkblue&quot;)
  ef&lt;-data.frame(
    date=as.Date(c(&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-01&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-02&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;,&quot;2021-03-03&quot;)),
    site=c(&quot;Castle&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Palace&quot;,&quot;Palace&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Palace&quot;,&quot;Palace&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Palace&quot;,&quot;Castle&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Palace&quot;,&quot;Palace&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Palace&quot;,&quot;Palace&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Castle&quot;,&quot;Temple&quot;,&quot;Temple&quot;,&quot;Palace&quot;),
    id=c(&quot;C123&quot;,&quot;T101&quot;,&quot;T93&quot;,&quot;T94&quot;,&quot;T95&quot;,&quot;T96&quot;,&quot;P102&quot;,&quot;P96&quot;,&quot;C126&quot;,&quot;C127&quot;,&quot;C128&quot;,&quot;T100&quot;,&quot;T98&quot;,&quot;P100&quot;,&quot;P98&quot;,&quot;C129&quot;,&quot;C130&quot;,&quot;C131&quot;,&quot;C132&quot;,&quot;C133&quot;,&quot;T104&quot;,&quot;T99&quot;,&quot;P99&quot;,&quot;C123&quot;,&quot;T101&quot;,&quot;T93&quot;,&quot;T94&quot;,&quot;T95&quot;,&quot;T96&quot;,&quot;P102&quot;,&quot;P96&quot;,&quot;C126&quot;,&quot;C127&quot;,&quot;C128&quot;,&quot;T100&quot;,&quot;T98&quot;,&quot;P100&quot;,&quot;P98&quot;,&quot;C129&quot;,&quot;C130&quot;,&quot;C131&quot;,&quot;C132&quot;,&quot;C133&quot;,&quot;T104&quot;,&quot;T99&quot;,&quot;P99&quot;),
    gainspend=c(&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Gain&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;,&quot;Spend&quot;),
    amount=c(6,14,34,31,3,10,6,14,2,16,16,14,1,1,15,11,8,7,2,10,15,4,3,NA,NA,4,5,NA,NA,NA,NA,NA,NA,2,NA,1,NA,3,NA,NA,2,NA,NA,2,NA,3))
  #▼ 3 day, points centered
  ggplot(ef,aes(date,site)) + 
    geom_point(aes(size=amount,color=gainspend),alpha=0.5) +
    scale_color_manual(values=ccode) +
    scale_size_continuous(range=c(1,15),breaks=c(5,10,20))
  #▼ 3 day, jitted
  ggplot(ef,aes(date,site)) + 
    geom_point(aes(size=amount,color=gainspend),alpha=0.5,position=position_jitter(w=0,h=0.2)) +
    scale_color_manual(values=ccode) +
    scale_size_continuous(range=c(1,15),breaks=c(5,10,20))
  </code></pre>