title: How can I maintain consistent box width in a boxplot where factor*group combination has no observations?
body: <p>I am trying to create a boxplot for 2 groups across several factors along with labels for the number of observations. When there are no observations for one group a one factor level, the box for the group with observations takes up the space of both and looks odd.</p>
  
  <p>Minimal example:</p>
  
  <pre><code>library(tidyverse)
  
  mtcars %&gt;%
    select(mpg, cyl,am) %&gt;%
    filter(!(cyl == 8 &amp; am == 0)) %&gt;%
    ggplot(aes(factor(cyl),mpg,fill=factor(am))) + 
    stat_boxplot(geom = "errorbar") + ## Draw horizontal lines across ends of whiskers
    geom_boxplot(outlier.shape=1, outlier.size=3, 
                 position =  position_dodge(width = 0.75)) +
    geom_text(data = mtcars %&gt;%
                select(mpg, cyl, am) %&gt;%
                filter(!(cyl == 8 &amp; am == 0)) %&gt;%
                group_by(cyl, am) %&gt;%
                summarize(Count = n(),
                        q3 = quantile(mpg, 0.75),
                        iqr = IQR(mpg),
                        lab_pos = max(ifelse(mpg &lt; q3+1.5*iqr, mpg, NA), na.rm = TRUE)),
                        aes(x= factor(cyl), y = lab_pos,label = paste0("n = ",Count, "\n")),
                    position = position_dodge(width = 0.75))
  </code></pre>
  
  <p>Which produces:</p>
  
  <p><a href="https://i.stack.imgur.com/jULdN.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jULdN.png" alt="enter image description here"></a></p>
  
  <p>Is there a way to make the box for <code>am(1)</code> at <code>cyl(8)</code> half the width, so it's consistent with the other boxes on the plot? I have tried to use fake data, but that results in a count label for <code>am(0)</code> at <code>cyl(8)</code>.</p>