The API can return geojson objects, which can be very useful forquickly creating maps of the DHS indicator data. These are large objectsthough, and can cause the API to return slowly if too much data isreturned.
In this demonstration we will be using 2 other packages,leaflet andgeojson.
# load our packagelibrary(rdhs)# install other packages# install.packages("geojson")# install.packages("leaflet")# make requestd<-dhs_data(countryIds ="SN",indicatorIds ="FE_FRTR_W_A15",surveyYearStart =2014,breakdown ="subnational",returnGeometry =TRUE,f ="geojson")# convert to spm<- geojsonio::as.json(d)nc<- geojsonio::geojson_sp(m)# plot using leafletpal<- leaflet::colorNumeric("viridis",NULL)leaflet::leaflet(nc[nc$IndicatorId=="FE_FRTR_W_A15",])%>% leaflet::addTiles()%>% leaflet::addPolygons(stroke =FALSE,smoothFactor =0.3,fillOpacity =1,fillColor =~pal(log10(Value)),label =~paste0(CharacteristicLabel,": ",formatC(Value,big.mark =",")))%>% leaflet::addLegend(pal = pal,values =~log10(Value),opacity =1.0,labFormat = leaflet::labelFormat(transform =function(x)round(10^x)),title =~Indicator[1])