Question

I wish to have multiple maps showing point values in Auckland, NZ. The problem is that I have a background shapefile (land) to add background detail to the map which means that the free scale x y scales to the whole Auckland Region rather than the points spatial extent.

So my question is: How do I achieve varying spatial extents based purely on the point layer and get facet_wrap to ignore the others?

Here is the current code:

map1 <- ggplot(walk, 
           aes(x=coords.x1, y=coords.x2, colour=UD_TOTAL, size=UD_TOTAL)
           ) +
      scale_colour_gradient(low="#003300", high="#00FF00", space="rgb") + 
      opts(panel.background=theme_rect(fill="#404040", colour = "#404040")) +
      quiet +
      pland + 
      geom_point() +
      facet_wrap(~School2, ncol=3, scales='free') 

map1

NB: This map is an attempt to mimic http://spatialanalysis.co.uk/2012/02/great-maps-ggplot2/

Beginner so unfortunately I am unable to post images.

Was it helpful?

Solution

Thanks to advice from Charlotte Wickham I have found the new feature 'annotation_map' which facet wrap ignores. I did not spot it in my research through the book but is found here: http://cran.r-project.org/web/packages/ggplot2/ggplot2.pdf.

The updated code is:

map1 <- ggplot(walk2, 
        aes(x=coords.x1, y=coords.x2, colour=UD_TOTAL, size=UD_TOTAL)) + 
        scale_colour_gradient(low="#003300", high="#00FF00", space="rgb") + 
        opts(panel.background=theme_rect(fill="#404040", colour = "#404040")) +
        annotation_map(BuiltEnv, fill="#4F4F4F", colour="#4F4F4F") +
        geom_point() +
        facet_wrap(~School2, ncol=3, scales='free') +
        coord_map(project="mercator")
map1
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top