Note that there are some explanatory texts on larger screens.

plurals
  1. POFacet with free scales but keep aspect ratio fixed
    primarykey
    data
    text
    <p>I am using ggplot to draw faceted maps and have been unable to work out how to allow "free" scales in each facet (so that small regions don't look too small) while keeping the x-y aspect ratio fixed.</p> <p>Here is a simplified example:</p> <pre><code>require(maps) require(ggplot2) map_nz &lt;- subset(fortify(map_data('nz')), region %in% c("South.Island ", "North.Island ")) gg_nz &lt;- qplot(long, lat, data=map_nz, geom="polygon", group=group) </code></pre> <p>I now have a plot of the North and South Islands of New Zealand. I can facet this and display it with a fixed aspect ratio like this:</p> <pre><code>gg_nz + coord_fixed() + facet_wrap(~region) </code></pre> <p>with a result that looks like this:</p> <p><img src="https://i.stack.imgur.com/AkVfM.png" alt="NZ map - fixed aspect ratio"></p> <p>Notice that there is quite a bit of space wasted in the North Island facet. I would like it to take up more of the available space. I can free up the scales like this:</p> <pre><code>gg_nz + facet_wrap(~region, scales="free") </code></pre> <p>with the following result:</p> <p><img src="https://i.stack.imgur.com/YKeIP.png" alt="NZ map - free scales"></p> <p>The problem is that the x-y aspect ratio is no longer 1:1 in each facet. I am happy to have each facet on a different scale, but within the facet I would like to preserve the aspect ratio.</p> <p>I tried the following without success:</p> <pre><code>gg_nz + facet_wrap(~region, scales="free") + coord_fixed() </code></pre> <p>Presumably the <code>scale</code> parameter in <code>facet_wrap</code> overrides <code>coord_fixed</code>. Any suggestions?</p> <p>UPDATE: to give a more dramatic illustration, here is the same phenomenon with some US states:</p> <p>Fixed coords (using <code>coord_fixed</code> or <code>coord_equal</code>):</p> <p><img src="https://i.stack.imgur.com/R7rpv.png" alt="US map - Fixed aspect"> Free coords (using <code>scales = free</code>):</p> <p><img src="https://i.stack.imgur.com/CStLw.png" alt="US map -Free scales"></p> <p>Neither of these maps is ideal: in the first, Delaware is tiny. In the second, the aspect ratios are quite distorted. New Jersey, which is a narrow state, is stretched too wide, for example.</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload