1

(I posted this on Stackoverflow, but thought this may be a better venue)

I am trying to generate a figure containing six choropleth maps in R. Currently my code looks something like this:

library(rgdal)
library(GISTools)

# code that loads data needed to generate choropleth maps not shown

par(mfrow = c(3,2), mar=c(0,0,0,0), oma=c(0,6,6,0))


choropleth(mn_county, mn_county$emppct.tert.2006, shades) 
mtext( 'Secondary', side=3, line=2)
mtext( '1998', side=2, line=2)

choropleth(mn_county, mn_county$emppct.tert.2006, shades) 
# choropleth maps are repeated in this post for simplicity
mtext( 'Tertiary', side=3, line=2)

choropleth(mn_county, mn_county$emppct.tert.2006, shades)
mtext( '2006', side=2, line=2)

choropleth(mn_county, mn_county$emppct.tert.2006, shades)
choropleth(mn_county, mn_county$emppct.tert.2006, shades)
mtext( '2014', side=2, line=2)

choropleth(mn_county, mn_county$emppct.tert.2006, shades)

The problem is, even though I set margins mar to be zero throughout, there are still big gaps between the columns (see below). Not just between the choropleth maps, but also between the row headings (1998, 2006, 2014) and the maps.

How can I reduce this wide space?

enter image description here

P.S. I've been trying to find a GIS shapefile which I can directly pull off from the internet (I don't think I can attach shapefiles in posts), but can't find one. Any idea how I can circumvent this problem?

2
  • What happens if you resize your graphics window? Make it thinner.
    – Spacedman
    Nov 29, 2016 at 17:23
  • There's sample data in the maptools package if you want to create a reproducible example, see, eg, the help for choropleth for usage.
    – Spacedman
    Nov 29, 2016 at 17:26

1 Answer 1

1

Use the choropleth example to create some sample data:

require(GISTools)
example(choropleth)

Then duplicate your work:

par(mfrow = c(3,2), mar=c(0,0,0,0), oma=c(0,6,6,0))
choropleth(sids,sids.rate,shades)
mtext( 'Secondary', side=3, line=2)
mtext( '1998', side=2, line=2)
choropleth(sids,sids.rate,shades)
mtext( 'Tertiary', side=3, line=2)
choropleth(sids,sids.rate,shades)
mtext( '2006', side=2, line=2)
choropleth(sids,sids.rate,shades)
choropleth(sids,sids.rate,shades)
mtext( '2014', side=2, line=2)
choropleth(sids,sids.rate,shades)

That gives:

enter image description here

But on resizing my graphics window it closes up the gaps:

enter image description here

Note that because of the shape of the map data here this looks best on a nearly-square graphics window, whereas your data will probably need a taller-than-wide window.

1

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.