Different Binwidth for Each Plot of a Facet
<p>Trying to understand assigning unique <code>binwidth</code> for each factor level in <code>geom_histogram</code>.
So far failed though. </p>

<p>Here is the reproducible data</p>

<pre><code>a &lt;- rnorm(10,7,0.1)
b &lt;- rnorm(10,13,5)
df &lt;- data.frame(data = c(a,b),group=c(rep("a",10),rep("b",10)))
kk &lt;- df%&gt;%
  group_by(group)%&gt;%
  mutate(bin=density(data)$bw)

binns &lt;- round(unique(kk$bin),digits = 2)  # to get each binwidth for each group

ggplot()+
  geom_histogram(data=kk,aes(x=data, fill=group),binwidth=binss)+
  facet_wrap(~group,scales=c("free_y"))

Error in seq.default(round_any(range[1], size, floor),    round_any(range[2],  : 
  'from' must be of length 1
Error in seq.default(round_any(range[1], size, floor), round_any(range[2],  : 
  'from' must be of length 1
Error in exists(name, envir = env, mode = mode) : 
  argument "env" is missing, with no default
</code></pre>

<p>Then I tried</p>

<pre><code>ggplot()+
  geom_histogram(data=kk,aes(x=data, fill=group),binwidth=c(binns[1],binns[2]))+
  facet_wrap(~group,scales=c("free_y"))
</code></pre>

<p>The same error happened. I couldn't understand why it is giving the same error.</p>