Here’s a demonstration of how easy it is to map with the R package rworldmap by Andy South. I map the ethnic representation scores in my 2009 JLS article, available from my Dataverse. I used the tab-delimited file, which contains the country name, Q-scores, R-scores, and a binary indicator of minority presence. I searched&replaced the tabs with commas, and added a new column for the ISO3 country codes.
After that, it’s just a few lines in R:
library(rworldmap)
dta <- read.csv("Representation.csv") # these are the data described above.
> head(dta)
gives:
Country ISO3 QScore RScore Present
1 Afghanistan AFG 0.803 0.697 1
2 Albania ALB 0.980 0.510 1
3 Algeria DZA NA NA 1
4 Andorra AND 0.980 0.000 0
5 Angola AGO NA NA 1
6 Antigua & Barbuda ATG 0.910 0.000 0
Next we have to identify the countries. joinCode
specifies that I used ISO3, nameJoinColumn
specifies the variable with the country abbreviations:
jcd <- joinCountryData2Map(dta, joinCode="ISO3", nameJoinColumn="ISO3")
Next a line from the package vignette that makes the plot use the space available.
par(mai=c(0,0,0.2,0),xaxs="i",yaxs="i")
Now, while mapCountryData(jcd, nameColumnToPlot="QScore")
would suffice to draw a map, I used some of the options available (e.g. a blue ocean, light grey for missing data), and drew the legend separately for a little extra control:
mapParams <- mapCountryData(jcd, nameColumnToPlot="QScore", addLegend=FALSE, mapTitle="Ethnic Representation Scores", oceanCol="light blue", missingCountryCol="light grey")
do.call(addMapLegend, c(mapParams, legendWidth=0.5, legendMar = 4))
The title is a bit off, but other than that, I’m pretty happy for a first cut with so little coding.
Ruedin, Didier. 2009. ‘Ethnic Group Representation in a Cross-National Comparison.’ The Journal of Legislative Studies 15 (4): 335–54. doi:10.1080/13572330903302448.