Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>To plot multiple <code>SpatialPolygons</code> objects on the same device, one approach is to specify the geographic extent you wish to plot first, and then using <code>plot(..., add=TRUE)</code>. This will add to the map only those points that are of interest.</p> <p>Plotting using a projection, (e.g. a polyconic projection) requires first using the <code>spTransform()</code> function in the <code>rgdal</code> package to make sure all the layers are in the same projection. </p> <pre><code>## Specify a geographic extent for the map ## by defining the top-left and bottom-right geographic coordinates mapExtent &lt;- rbind(c(-156, 80), c(-68, 19)) ## Specify the required projection using a proj4 string ## Use http://www.spatialreference.org/ to find the required string ## Polyconic for North America newProj &lt;- CRS("+proj=poly +lat_0=0 +lon_0=-100 +x_0=0 +y_0=0 +ellps=WGS84 +datum=WGS84 +units=m +no_defs") ## Project the map extent (first need to specify that it is longlat) mapExtentPr &lt;- spTransform(SpatialPoints(mapExtent, proj4string=CRS("+proj=longlat")), newProj) ## Project other layers can1Pr &lt;- spTransform(can1, newProj) us1Pr &lt;- spTransform(us1, newProj) ## Plot each projected layer, beginning with the projected extent plot(mapExtentPr, pch=NA) plot(can1Pr, border="white", col="lightgrey", add=TRUE) plot(us1Pr, border="white", col="lightgrey", add=TRUE) </code></pre> <p>Adding other features to the map, such as highlighting jurisdictions of interest, can easily be done using the same approach: </p> <pre><code>## Highlight provinces and states of interest theseJurisdictions &lt;- c("British Columbia", "Yukon", "Northwest Territories", "Alberta", "Montana", "Alaska") plot(can1Pr[can1Pr$NAME_1 %in% theseJurisdictions, ], border="white", col="pink", add=TRUE) plot(us1Pr[us1Pr$NAME_1 %in% theseJurisdictions, ], border="white", col="pink", add=TRUE) </code></pre> <p>Here is the result:</p> <p><img src="https://i.stack.imgur.com/t1x2A.jpg" alt="enter image description here"></p> <p>Add grid-lines when a projection is used is sufficiently complex that it requires another post, I think. Looks as if @Mark Miller as added it below! </p>
    singulars
    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.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      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