title: Understanding facet_grid scale="free"
body: <p>I want to use facet_grid with stat_compare_means and have individual scales for y. I thought scale = &quot;free&quot; would take care of it, but it doesn't. Level &quot;B&quot; in my Name factor is not scaled properly.</p>
  <pre><code>library(tidyverse) 
  library(ggpubr) 
  
  set.seed(2)
  
  my_comparisons &lt;- list(c(&quot;Cond1&quot;,&quot;Cond2&quot;),
                          c(&quot;Cond2&quot;,&quot;Cond3&quot;),
                          c(&quot;Cond1&quot;,&quot;Cond3&quot;))
  
  nrName  &lt;- 4
  nrCond  &lt;- 3
  nrValue &lt;- 5
  
  Name      &lt;-  rep(c(&quot;A&quot;,&quot;B&quot;,&quot;C&quot;,&quot;D&quot;),each=nrValue*nrCond)
  Condition &lt;-  rep(c(&quot;Cond1&quot;,&quot;Cond2&quot;,&quot;Cond3&quot;),length.out=nrName*nrCond*nrValue)
  Score     &lt;-  c(rnorm(nrValue*nrCond,6,1),rnorm(nrValue*nrCond,0.01,0.01),rnorm(nrValue*nrCond,7,1),rnorm(nrValue*nrCond,7,1))
  
  df &lt;- data.frame(Name = Name, Condition = Condition, Score = Score)
  
   plt &lt;- ggplot(df,
               aes(x= Condition,y= Score, fill= Condition))+  
     #geom_flat_violin(position = position_nudge(x = .2),adjust = 2)+
     geom_point(position = position_jitter(width = .15), size = .25)+
     geom_boxplot(outlier.shape = NA, alpha = 0.3, width = .1, colour = &quot;BLACK&quot;) +
     facet_grid(reformulate(&quot;Name&quot;,&quot;.&quot;),scales = 'free')+
     scale_y_continuous(expand = expansion(mult = c(0, 0.1)))+
     
     stat_compare_means(
       comparisons = my_comparisons,
       method = &quot;t.test&quot;,paired = TRUE,
       label.y.npc = 0.1)
  
  print(plt)
  </code></pre>
  <p><a href="https://i.stack.imgur.com/LK5vo.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LK5vo.png" alt="with stat_compare_means" /></a></p>
  <p>I thought it might be related to the labels in stat_compare_means. But removing stat_compare_means yields similar result.</p>
  <p><a href="https://i.stack.imgur.com/XDv53.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/XDv53.png" alt="without stat_compare_means " /></a></p>
  <p>What am I not considering here?</p>
  <p>I see my confusion now. As RonakShah pointed out correctly, I use geom_flat_violin from the the PupillometryR in my original code. I wanted to simplify the problem when I wrote the post here which is the reason why I showed the boxplots. If I add the line with the geom_flat_vioilin back in, and use greom_wrap as suggested by Suren, the scale = &quot;free&quot; option doesn't work anymore.</p>
  <pre><code>ggplot(df,
           aes(x= Condition,y= Score,fill= Condition))+  
  geom_flat_violin(position = position_nudge(x = .2))+
  geom_point(position = position_jitter(width = .15), size = .25)+
  geom_boxplot(outlier.shape = NA, alpha = 0.3, width = .1, colour = &quot;BLACK&quot;) +
  facet_wrap(reformulate(&quot;Name&quot;,&quot;.&quot;),scales = 'free',nrow = 1)+
  scale_y_continuous(expand = expansion(mult = c(0, 0.1)))
  </code></pre>
  <p><a href="https://i.stack.imgur.com/55zvJ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/55zvJ.png" alt="Geom_flat_violin + geom_wrap" /></a></p>
  <p>I guess I have to check out the geom_flat_violin function for further debuging.</p>