dipetkov / eems

Estimating Effective Migration Surfaces
GNU General Public License v2.0
102 stars 28 forks source link

Question about adding geographic map #45

Closed guojingfang123 closed 3 years ago

guojingfang123 commented 4 years ago

Hi Desislava, thank you very much for your detailed introduction of EEMS. I have a question about adding geographic map. I can add borders to countries. Can boundaries be added within countries?For example, add the provinces of China. Looking forward to your reply. Best, Hanna

dipetkov commented 3 years ago

Yes. There is an example how to that in the documentation. You can look up the documentation with ?eems.plots. The relevant example adds a map of Africa on top of the migration plot. Any map that is projected correctly by sp::spTransform can be added in a similar way.

# Apply the Mercator projection and add the map of Africa
# Don't forget to apply the same projection to the map as well
map_world <- getMap()
map_africa <- map_world[which(map_world@data$continent == "Africa"), ]
map_africa <- spTransform(map_africa, CRS(projection_mercator))
eems.plots(
  mcmcpath = eems_results,
  plotpath = paste0(name_figures, "-shapefile-projected"),
  longlat = TRUE,
  projection.in = projection_none,
  projection.out = projection_mercator,
  m.plot.xy = {
    plot(map_africa, col = NA, add = TRUE)
  },
  q.plot.xy = {
    plot(map_africa, col = NA, add = TRUE)
  }
)