JGCRI / rmap

Mapping software with pre-loaded global and local maps
https://jgcri.github.io/rmap/
Other
7 stars 0 forks source link

Map Projections #41

Closed ejarbuck closed 2 years ago

ejarbuck commented 3 years ago

Hi, this is a very impressive tool for data visualization with GCAM (and other applications)! I had a few questions for Zarrar and Chris yesterday at the GCAM Community Meeting. I have resolved how to plot data on SubRegions for Canada and have no further questions about that at this time. Another question I have is whether it might be possible to plot maps in different projections? (I think it is Mercator projection by default).

zarrarkhan commented 3 years ago

Thanks for the suggestion. The current projections are geographic (lat/lon) datum: WGS84. We will add a "projection" argument so you can set your own projection using a proj4string or EPSG number.


Yes for the Canadian provinces, I just updated rmap so it allows you to use data labels for cropped shapes. So please update to the latest version and then you can produce the provinces as well as label them as follows:

Documentation on sub-setting a shape: https://jgcri.github.io/rmap/articles/vignette_map.html#subset-existing-shape

(UPDATED: 22 Mar 2022 after switch to sf)

library(rmap); library(dplyr)
shapeSubset <- rmap::mapStates # Read in World States shape file
shapeSubset <- shapeSubset %>% dplyr::filter(region == "Canada")
m1<-rmap::map(data=shapeSubset,
          labels=T,
          labelSize = 3,
          labelFill = "white",
          labelAlpha = 0.6,
          labelRepel = 2,
          underLayer=rmap::mapCountriesUS52,
          background=T,
          zoom = -1) 

map

zarrarkhan commented 2 years ago

@ejarbuck We have added functionality to change the projection. Simply assign a proj4 string to the new crs argument. You can get these from https://epsg.io/54032.

Example documentation is here: https://jgcri.github.io/rmap/articles/vignette_map.html#projections

For your particular case:

library(rmap); library(dplyr)
shapeSubset <- rmap::mapStates # Read in World States shape file
shapeSubset <- shapeSubset %>% dplyr::filter(region == "Canada")
m2 <- rmap::map(data=shapeSubset,
              labels=T,
              labelSize = 3,
              labelFill = "white",
              labelAlpha = 0.6,
              labelRepel = 2,
              underLayer=rmap::mapCountriesUS52,
              background=T,
              crs="+proj=lcc +lat_1=49 +lat_2=77 +lat_0=0 +lon_0=-95 +x_0=0 +y_0=0 +datum=NAD83 +units=m +no_defs")

map