geom_rect + coord_map = very slow
<p>I am plotting a map of Norway with an area of interest highlighted with a red rectangle using <code>ggplot2</code>. If I omit the <code>geom_rect</code> or <code>coord_map</code>, the map plots very quickly (&lt; 1 seconds). If I use both - which I need to - it is extremely slow to print and render (about five minutes).</p>

<p>I presume this is something to do with the munching - projecting the rectangle onto the new coordinate system. Is there a way to control this?</p>

<pre><code>library(ggplot2)
library(maps)
library(mapdata)


xlim &lt;- c(5, 10)
ylim &lt;- c(60, 62)

norwaymap &lt;- map_data("worldHires", "Norway")
a &lt;- ggplot(norwaymap, aes(x = long, y = lat, group = group)) +
  geom_polygon(colour = NA, fill = "grey60") +
  geom_rect(xmin = xlim[1], xmax = xlim[2], ymin = ylim[1], ymax = ylim[2], 
    colour = "red", fill = NA) +
  coord_map(xlim = c(3, 33), ylim = c(57, 72))
print(a) # super slow
</code></pre>

<p>Using the low resolution map makes the map plotting much faster (about 10 seconds).</p>