title: Adding significance brackets between bars with subgroups in bar plot ggplot2
body: <p>I am trying to create a figure with brackets indicating significance between sublevels of my bar plot. The goal is to create something that looks like this based on results from a Wilcoxon test:</p>
  <p><a href="https://i.stack.imgur.com/qkX96.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/qkX96.png" alt="enter image description here" /></a></p>
  <p>However, I can't seem to figure out how to include brackets that compare the sublevels (Active 1 Week Post to Sham 1 Week Post; Active 8 Weeks Post to Sham 8 Weeks Post).</p>
  <p>Here is my data:</p>
  <pre><code>dat_ex &lt;- dput(dat_ex)
  structure(list(id = c(&quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, 
  &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 1&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, &quot;Participant 2&quot;, 
  &quot;Participant 2&quot;), item_num = c(1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 
  6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 
  15, 15, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 
  10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 1, 1, 2, 2, 3, 
  3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 
  13, 13, 14, 14, 15, 15, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 
  7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 
  1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 
  11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 1, 1, 2, 2, 3, 3, 4, 
  4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 
  13, 14, 14, 15, 15, 1, 1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 
  8, 8, 9, 9, 10, 10, 11, 11, 12, 12, 13, 13, 14, 14, 15, 15, 1, 
  1, 2, 2, 3, 3, 4, 4, 5, 5, 6, 6, 7, 7, 8, 8, 9, 9, 10, 10, 11, 
  11, 12, 12, 13, 13, 14, 14, 15, 15), tdcs = c(&quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, 
  &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, 
  &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;, &quot;sham&quot;, &quot;active&quot;
  ), One_Week_Post = c(1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 
  1, 0, 0, 1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 
  1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 
  0, 0, 1, 1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 
  1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 
  1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 
  1, 1, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 
  1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1, 1, 1, 
  1, 1, 0, 1, 1, 1, 0, 1, 1, 1, 0, 1, 1, 0, 0, 1, 0, 1, 1, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 1, 1, 1, 1, 0, 0, 0, 0, 
  0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 0, 0, 1, 1), time_point2 = c(&quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, 
  &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Baseline&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, 
  &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;, &quot;Eight_Weeks_Post&quot;), 
      score = c(1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, 
      1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 
      1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 
      1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 
      1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 
      1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
      1, 0, 0, 0, 0, 1, 1, 1, 1, 1, 0, 1, 0, 0, 0, 0, 0, 0, 0, 
      0, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 1, 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 1, 1, 1, 1, 
      1, 1, 0, 0, 0, 0, 1, 1, 0, 1, 0, 1, 0, 1, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 1, 1, 1, 1, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0), change = c(&quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, 
      &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto1&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, 
      &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;, &quot;Bto8&quot;), 
      chgbroad = c(0, 0, 0, 0, -1, 0, 0, 0, -1, 0, 0, 1, 0, 1, 
      1, -1, -1, 0, -1, 0, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 
      -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
      0, -1, 1, 0, 1, 0, 0, 1, 1, 0, 0, 0, 0, -1, 0, 0, 0, -1, 
      0, 0, 1, 0, 1, 1, -1, -1, 0, -1, 0, 1, -1, 0, 0, 0, 0, 0, 
      0, 0, 0, 1, 1, -1, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 0, -1, 1, 0, 1, 0, 0, 1, 1, 0, -1, 0, 0, 0, 
      0, 0, 0, 0, -1, -1, 0, 0, 1, 1, -1, 0, -1, 0, -1, 1, -1, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 0, 0, 0, 0, 0, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 0, 0, 0, 0, 0, 
      0, -1, 0, 0, 0, 0, 0, 0, 0, -1, -1, 0, 0, 1, 1, -1, 0, -1, 
      0, -1, 1, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 0, -1, 
      0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, -1, 0, -1, 
      0, 0, 0, 0, 0)), row.names = c(NA, -240L), class = c(&quot;tbl_df&quot;, 
  &quot;tbl&quot;, &quot;data.frame&quot;))
  
  </code></pre>
  <p>And here is the code I have for the plot without brackets:</p>
  <pre><code>sum_dat_ex &lt;-
    dat_ex %&gt;%
    group_by(id,tdcs, change) %&gt;%
    summarise(chgacc = mean(chgbroad), se = std.error(chgbroad), sd = sd(chgbroad)) %&gt;%
    mutate(chgacc = if_else(chgacc == 0,-0.0017,chgacc)) %&gt;%
    mutate(se = if_else(chgacc &lt; 0, se*-1,se)) %&gt;%
    mutate(ast_space = if_else(chgacc &lt; 0, -0.02,0.02)) %&gt;%
    mutate(signif_Bto1 = (if_else((id == 'Participant 2' &amp; tdcs == 'active' &amp; change == 'Bto1'), '1','0'))) %&gt;%
    mutate(signif_Bto8 = (if_else((id == 'Participant 1' &amp; tdcs == 'sham' &amp; change == 'Bto8'),'1','0')))
  sum_dat_ex
  
  
  # Creating Barplot:
  
  colorpicks &lt;- c(&quot;blue&quot;, &quot;red&quot;)
  
  barplot &lt;-ggplot(data=sum_dat_ex,
                             aes(x=tdcs, y=chgacc, fill = change)) +
    #scale_fill_manual(&quot;change&quot;,name = &quot;Follow up Time Point&quot;, values = colorpicks)+
    geom_col(width = 0.7, position = position_dodge(0.7)) +
    facet_wrap(~id, dir = &quot;h&quot;) +
    scale_fill_manual(values = colorpicks, labels = c('1 Week Post','8 Weeks Post'))+
    geom_text(data = sum_dat_ex[sum_dat_ex$signif_Bto1 == &quot;1&quot;, ], 
              aes(y=chgacc + se + ast_space, label=&quot;*&quot;), size=7, nudge_x = -0.175)+ #  y=chgacc + (-1*.02), nudge_x = 0.25
    geom_text(data = sum_dat_ex[sum_dat_ex$signif_Bto8 == &quot;1&quot;, ],
              aes(y=chgacc + se + ast_space, label=&quot;*&quot;), size=7, nudge_x = 0.175)+ #  y=chgacc + (-1*.02), nudge_x = 0.25
    scale_x_discrete(labels = c('Active','Sham'))+ # Only needed for graphs on the bottom
    scale_y_continuous(labels = scales::label_percent(accuracy = 1), limits = (c(-.35,.4))) +
    labs(y = &quot;Change from Baseline&quot;, fill = 'Follow up Time Point')+
    geom_errorbar(aes(ymin=chgacc-se,ymax=chgacc+se), width = 0, position = position_dodge(.7))
  barplot
  </code></pre>
  <p>Here is what I have attempted to create brackets:</p>
  <pre><code>stat.test1 &lt;- dat_ex %&gt;% 
    dplyr::filter(change == 'Bto1') %&gt;%
    group_by(id) %&gt;%
    wilcox_test(chgbroad ~ tdcs) %&gt;%
    adjust_pvalue(method = &quot;fdr&quot;) %&gt;%
    add_significance(&quot;p.adj&quot;)
  stat.test1 
  
  stat.test1 &lt;- stat.test1 %&gt;% add_xy_position(x = 'tdcs')
  barplot+ stat_pvalue_manual(stat.test1)
  
  
  stat.test2 &lt;- dat_ex %&gt;% 
    dplyr::filter(change == 'Bto8') %&gt;%
    group_by(id) %&gt;%
    wilcox_test(chgbroad ~ tdcs) %&gt;%
    adjust_pvalue(method = &quot;fdr&quot;) %&gt;%
    add_significance(&quot;p.adj&quot;)
  stat.test2
  
  
  stat.test1 &lt;- stat.test1 %&gt;% add_xy_position(x = 'tdcs')
  barplot + stat_pvalue_manual(stat.test1)
  </code></pre>
  <p>But the error I get is &quot;Error in FUN(X[[i]], ...) : object 'change' not found&quot;</p>
  <p>Is it possible to do this? Or do I need to create the brackets manually?</p>