Tuesday, February 18, 2020

SDG Atlas in R, requiring worldborder/TM_WORLD_BORDERS-0.3

#sdgatlas.R
#require getwdi.do in Stata [below], 

# and WDI document to know handle or var name of theme
# this may require filling in missing values
#to draw map of SDG atlas for countries around the world 

# based on World Bank's World Development Indicators
setwd('C:/data/GDI/GlobalInqSocDev2017-2018')
require(foreign)
require(rgdal)
require(tmap)
world <- readOGR(dsn = './worldborder', layer= "TM_WORLD_BORDERS-0.3")
#based on WDI :32
wtheme <- read.dta('worldtheme.dta')
wtheme$countrycode <- as.factor(wtheme$countrycode)
world@data = data.frame(world@data, wtheme[match(world@data[, "ISO3"], wtheme[, "countrycode"]), ])
#tm_shape(world) + tm_polygons("si_pov_nahc", style="quantile")
#dev.copy(png, 'SDGpov.png')
tm_shape(world) + tm_polygons("si_pov_gini", style="quantile")
dev.copy(png, 'mapgini.png')
dev.off()

#tm_shape(world) + tm_polygons("si_pov_nahc", style="quantile")
#dev.copy(png, 'mappoverty.png')
#dev.off()

*getwdi.do: a simple way to get World Indicators
cd ~/GDI2017  //then consult WDI to get var name of theme: si.pov.nahc
tempfile tmp
wbopendata, language(en - English) indicator(si.pov.nahc) long clear latest
sort countrycode
save `tmp', replace
sysuse world-d, clear
merge countrycode using `tmp'
*may want to fill in missing values
*spmap  si_pov_nahc using "world-c.dta", id(_ID)
saveold worldtheme, version(12)

0 Comments:

Post a Comment

<< Home