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

Fatal error: Uncaught PDOException: SQLSTATE[HY000]: General error: 8 attempt to write a readonly database in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php:78 Stack trace: #0 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(78): PDOStatement->execute(Array) #1 /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php(30): insert_webrequest_('/notes/developm...', 1745510210, '18.221.207.166', 'Mozilla/5.0 App...', NULL) #2 /home/httpd/vhosts/renenyffenegger.ch/httpsdocs/notes/development/languages/R/packages/rworldmap/index(124): insert_webrequest() #3 {main} thrown in /home/httpd/vhosts/renenyffenegger.ch/php/web-request-database.php on line 78