chrisvwn / Rnightlights

R package to extract data from satellite nightlights.
GNU General Public License v3.0
47 stars 14 forks source link

Plotting a map #25

Closed nreguera closed 5 years ago

nreguera commented 5 years ago

Hello Chris,

I am trying to plot a map with the sum of radiances by any admin level using R. First I have used the package sp and the file rds downloaded by Rnighlights package to plot only the shape of the country (in this case Myanmar - MMR) with the following code:

library(sp)
map_MMR <- readRDS("E:/.Rnightlights/polygons/SHP_MMR_GADM-3.6.rds")
plot(map_MMR)

but I get the following error:

Error in xy.coords(x, y, xlabel, ylabel, log) : 'x' is a list, but does not have components 'x' and 'y'

Is this related to the file or to the way I try to pain it? I am thinking that maybe I may use the files inside the folder "SHP_MMR_GADM-3.6", i.e. "gadm36_MMR_3.shp", should I?

Thanks.

chrisvwn commented 5 years ago

Hi Natxo,

You can access the cached GADM maps using 2 methods.

1RDS - The .RDS contains a list with each slot containing a layer. So for your code you could try:

plot(map_MMR[[1]])

2.Shapefile folder - The layers are represented as files named with the layer index. You can use the following code to plot a layer:

plot(rgdal::readOGR(dsn = "E:/.Rnightlights/polygons/SHP_MMR_GADM-3.6", layer = "gadm36_MMR_1"))
nreguera commented 5 years ago

Great, thanks.