title: How to convert to stat_summary_2d?
body: <p>I am using 'flights' data set from 'nycflights13' package. I was required to convert to code containing 'stat_summary_2d' from the original code:</p>
  <pre><code>    flights %&gt;%
    mutate(cancel = 1*(dep_time %&gt;% is.na)) %&gt;%
    group_by(carrier, origin) %&gt;%
    summarise(cancel = 100*mean(cancel, na.rm = T)) %&gt;%
    ggplot() +
    geom_tile(aes(origin, carrier, fill = cancel)) +
    geom_text(aes(origin, carrier, label = round(cancel,1)),
              col = &quot;blue&quot;, size = 5) +
    scale_fill_distiller(&quot;Cancel Ratio&quot;, palette = &quot;RdYlGn&quot;) +
    theme_bw()
  </code></pre>
  <p>In the data set the missing value of the 'dep_time' variable means a cancelled flight, and the variable 'cancel' is created by calculating the  proportion of cancelled flights over the scheduled flights.
  Below is how I apply 'stat_summary_2d' to convert the original code:</p>
  <pre><code>    flights %&gt;%
    mutate(cancel = 1*(dep_time %&gt;% is.na)) %&gt;%
    ggplot() +
    stat_summary_2d(aes(carrier, origin, z = cancel)) +
    geom_text(data = flights %&gt;% group_by(carrier, origin) %&gt;%
                summarize(cancel = 100*mean(cancel, na.rm = T)) %&gt;% ungroup,
              aes(factor(carrier), origin, label = round(cancel,1)),
              col = &quot;blue&quot;, size = 5) +
    scale_fill_distiller(&quot;Cancel Ratio&quot;, palette = &quot;RdYlGn&quot;) +
    theme_bw()
  </code></pre>
  <p>When I execute my code, the error is</p>
  <blockquote>
  <pre><code>&gt; Error in summarize()`: ! Problem while computing `cancel = 100 *
  &gt; mean(cancel, na.rm = T)`. i The error occurred in group 1: carrier =
  &gt; &quot;9E&quot;, origin = &quot;EWR&quot;.
  </code></pre>
  </blockquote>
  <p>Could anyone tell me how to fix this problem? Thank you so much!</p>