Take controll over the maximum counts in ggplot2 + geom_bin2d?
<p>I have a problem with the <code>ggplot2</code> and the <code>geom_bin2d()</code>-Function. I would like to produce <code>heatmap-Plots</code> of the same area throughout different points in time. My problem is that I want to take control over the counts. Is it possible to fix the maximum counts, for example form 0 to 30 (see example). If I plot a new sample with more points, there is always a shift in the counts (in my example from a maximum of 15 to a maximum of 30). In the package <code>"hexbin"</code> this is possible by the command "mincnt" and "maxcnt". With "maxcnt=30" I can fix the maximum counts to 30 in both plots. But I don't get it to do this with <code>ggplot2 + geom_bin2d...</code> Do you have an idea? I didn't found something about this here or elsewhere. Thanks a lot!</p>

<p><a href="http://i.stack.imgur.com/9EmTd.jpg" rel="nofollow">maximum counts of 15</a> </p>

<p><a href="http://i.stack.imgur.com/WaivE.jpg" rel="nofollow">maximum counts of 30</a></p>

<pre><code>library(ggplot2)
set.seed(1)
dat1 &lt;- data.frame(x = rnorm(1000), y = rnorm(1000))

p1 &lt;- ggplot(dat1, aes(x = x, y = y)) + geom_bin2d(bins=25) +
  scale_fill_gradient(low = "blue", high = "red")
plot(p1)

set.seed(2)
dat2 &lt;- data.frame(x = rnorm(2000), y = rnorm(2000))
p2 &lt;- ggplot(dat2, aes(x = x, y = y)) + geom_bin2d(bins=25) +
  scale_fill_gradient(low = "blue", high = "red")
plot(p2)
</code></pre>