title: Adding counts to ggmosaic, can this be done simpler?
body: <p>I would like to make a mosaic plot using the ggmosaic package and add the counts as shown in the example below.</p>
  
  <p>The example sort of works, but I find the structure of the code quite ugly. 
  Do you have any suggestions on how I can improve the code, to make it more reusable?</p>
  
  <p>Especially the need for storing an early version of the plot in a temporary variable seems wrong compared to what usually can be achieved using ggplot2.</p>
  
  <pre><code>library(tidyverse)
  library(ggmosaic)
  #&gt; Indlæser krævet pakke: productplots
  #&gt; 
  #&gt; Vedhæfter pakke: 'ggmosaic'
  #&gt; De følgende objekter er maskerede fra 'package:productplots':
  #&gt; 
  #&gt;     ddecker, hspine, mosaic, prodcalc, spine, vspine
  
  data &lt;- tribble(~a, ~b, 
                  1, 1, 
                  1, 1, 
                  1, 1, 
                  1, 2, 
                  2, 1,
                  2, 2, 
                  3, 2)
  
  p &lt;- ggplot(data) + 
    geom_mosaic(aes(x=product(b, a), fill=as.factor(b)))
  
  p + 
    geom_label(data = ggplot_build(p)$data %&gt;% as.data.frame() %&gt;% filter(.wt &gt; 0), 
               aes(x = (xmin + xmax)/2, 
                   y = (ymin + ymax)/2, 
                   label = .wt))
  </code></pre>
  
  <p><img src="https://i.imgur.com/zijMymk.png" alt=""></p>
  
  <p>Created on 2018-05-08 by the <a href="http://reprex.tidyverse.org" rel="noreferrer">reprex package</a> (v0.2.0).</p>