simple (I think) question: How do I add names to the countries?

323 views
Skip to first unread message

Drew esoa

unread,
Oct 6, 2015, 3:38:41 PM10/6/15
to rworldmap
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. 

I appreciate any help or direction with this problem,

Cheers-

Jean-Baka Domelevo Entfellner

unread,
Oct 7, 2015, 10:10:10 AM10/7/15
to Drew esoa, rworldmap
Hello,

Why not using labelCountries() if you want to add names directly onto the plot?
http://www.inside-r.org/packages/cran/rworldmap/docs/labelCountries

Regards,
Jean-Baka
> --
> You received this message because you are subscribed to the Google Groups
> "rworldmap" group.
> To post to this group, send email to rwor...@googlegroups.com.
> Visit this group at http://groups.google.com/group/rworldmap.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/rworldmap/d457d904-5d62-48dd-bba9-5ebbe624bd19%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages