0

I have downloaded a Spatial Polygons Data Frame from gadm.org but the map is slightly outdated and the names of the regions are in Latin. I need to change the names to Cyrillic and merge some of the regions. Is this something that would be better done on the Spatial Polygons Data Frame or in tmap while plotting?

So far I have tried to extract separate data frames from the Spatial Polygons Data Frame and make the changes there, but I feel like I'm not going down the right path. I know I can plot those with ggplot2 as explained here, but I can't find any reference about using the same method being possible with tmap.

novica
  • 655
  • 4
  • 11
  • In terms of "better", I am biased and would say is always better to do your polygon manipulation with, say the [sf](https://cran.r-project.org/web/packages/sf/index.html) package and then plot with whatever you wish - `tmap` or `ggplot2` or `leaflet` or `mapview`. That is, use each package for what was mainly designed. Do not expect to do everything with one package even if is somehow possible. So, first get the data in the shape you need it or required by the plotting package, then plot it. – Valentin_Ștefan May 05 '19 at 08:57

1 Answers1

0

It is difficult to quantify "better" - but the work you describe will be certainly easier and faster if you used the sf package format, rather than Spatial Polygons from sp package. It is available on the GADM site as well.

The sf spatial objects are modified data frames, meaning you could apply to them the standard data wrangling methods - such as dplyr::mutate() to manipulate the names etc.

As for the merging of regions you could use a workflow based on sf::st_union() that I described a while back in a blog post: https://www.jla-data.net/eng/dissolving-polygons-in-sf-environment/ - it even uses tmap as a plotting tool, so you should find the workflow familiar.

And lastly a warning with regards to the five years old question about plotting maps with ggplot you linke: the approach using fortify() is by now obsolete, you will get much better results using the geom_sf() function of the current ggplot.

Jindra Lacko
  • 7,814
  • 3
  • 22
  • 44