Hi all, I have read through the CRAN pdf for rworldmap and am still scratching my head as to how to add country names to my plot. My code is below:
library(WDI)
library(rworldmap)
library(RColorBrewer)
library(raster)
##physicians per 1000 people: SH.MED.PHYS.ZS
##co2 emissions KT total: EN.ATM.CO2E.KT
##pull data on CO2 Emissions using WDI plugin
datamap = WDI(indicator = "SH.MED.PHYS.ZS", start=2010, end=2010)
##sPDF file created (Spatial Polygons Data Frame) for mapping use
data(datamap)
sPDF <- joinCountryData2Map( datamap
,joinCode = "ISO2"
,nameJoinColumn = "iso2c"
,nameCountryColumn = 'country' )
mapDevice() ##create world map using data specified
mapParams <- mapCountryData(sPDF
,nameColumnToPlot='SH.MED.PHYS.ZS'
,addLegend=FALSE
##(set to specify region) e.g.
,mapRegion='Europe'
,catMethod='logfixedWidth'
,numCats=24
,colourPalette='heat' )
country_coord <- data.frame(coordinates(pdf1),stringsAsFactors=F)
text(pdf1, labels="NAME")
#adding legend for data - note: this is to customize the legend
##(if addLegend above was True mapDevice would use default option)
do.call(addMapLegend
,c(mapParams
,legendLabels="all"
,legendWidth=0.5
,legendIntervals="data"
,legendMar = 3))
You will notice that I tried implementing a solution using the raster package to no avail.