ropensci / naijR

R package on Nigeria and for Nigeria
https://docs.ropensci.org/naijR/
GNU General Public License v3.0
12 stars 3 forks source link

Integration with tmaps #37

Open josoga2 opened 2 years ago

josoga2 commented 2 years ago

Hello @BroVic , Just out of curiosity, is it possible to get the geometry data for state-level data for later use with tmaps? I specified tmaps because of its interactive mode.

BroVic commented 2 years ago

Hi @josoga2

The map_ng function returns a list as specified in ?maps::map.. The documentation says this about the return value:

The return value is a list with x, y, range, and names components. This object can be used as a database for successive calls to map and functions. If fill is FALSE, the x and y vectors are the coordinates of successive polylines, separated by NAs. If fill is TRUE, the x and y vectors have coordinates of successive polygons, again separated by NAs. Thus the return value can be handed directly to lines or polygon, as appropriate

I think tmaps expects "simple feature" objects, so if you work with the sf package, I suppose you can use this list to create objects that can be passed on to tmaps. Although the naijR package is not strictly designed for geospatial analyses, one can look into providing richer objects in future.

BroVic commented 1 year ago

@josoga2 check out this code for a simple way to use this package with {tmap}.

I am yet to decide whether to bake this functionality into the package or not.