Search notes:

R package: rworldmap

Installing

Installing the package with install.packages('rworldmap') required gfortran. In Arch Linux, I was able to install gfortran with sudo pacman gnu-fortran

Highlighting some countries in the World

The following example colors some countries according to a hypothetical »foo« value
#
#   https://stackoverflow.com/q/29119074/180275
#
X11()
library(rworldmap)

country_foo = read.table(text='country foo
Angola        32
Brazil        31
Czechia       28
Egypt         87
India         69
Mexico        52
Poland        48
Spain         59
Zimbbabwe     62',
 header=T)

map <- joinCountryData2Map(
       country_foo,
       joinCode       = "NAME",
       nameJoinColumn = "country"
     )

png('img/highlight-countries.png', width=400, height=300)
par(mar=c(0, 0, 1, 0))
mapCountryData(map,
   nameColumnToPlot  = 'foo'        ,
   catMethod         = 'fixedWidth'
)

# z <- locator(1)
Github repository about-r, path: /packages/rworldmap/highlight-countries.R

Highlighting countries in Europe

X11()
library(rworldmap)

countries <- data.frame(
      country = c('AUT', 'CHE', 'DEU', 'CHE', 'ESP', 'FRA', 'ITA', 'NOR', 'POL', 'SWE'),
      foo     = c(   1 ,    3 ,    4 ,    1 ,    1 ,    2 ,    2 ,    3 ,    3,     2 )
)

map <- joinCountryData2Map(
       countries,
       joinCode       = "ISO3", # ISO 3166.1 / alpha 3
       nameJoinColumn = "country"
     )

png('img/highlight-countries-in-europe.png', width=400, height=400)
par(mar=c(0, 0, 1, 0))
mapCountryData(map,
   nameColumnToPlot  = 'foo'        ,
   catMethod         = 'categorical',
   mapRegion         = 'Europe'     ,
   oceanCol          = 'white'      ,
   missingCountryCol = 'light grey' ,
   borderCol         = 'white'
)

# z <- locator(1)
Github repository about-r, path: /packages/rworldmap/highlight-countries-in-europe.R

See also

The maps package
R packages
Data visualization: map

Index