Created
March 28, 2012 16:20
-
-
Save patperu/2227927 to your computer and use it in GitHub Desktop.
Choropleth map in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# | |
# Map the 'Purchasing Power Parity (PPP) | |
# converted GDP per capita' from pwt7.0 | |
# using a shapefile | |
# | |
library(maptools) | |
library(pwt) | |
library(classInt) | |
# Download a worldmap as shapefile from | |
# http://thematicmapping.org/downloads/world_borders.php | |
wshp <- readShapeSpatial("TM_WORLD_BORDERS-0.3.shp") | |
head(wshp@data) | |
plot(wshp, lwd=1) | |
# rownames as ID | |
wshp@data$ID <- rownames(wshp@data) | |
# using data from the Penn World Tables - year "2008" | |
data("pwt7.0") | |
z <- pwt7.0[pwt7.0$year == "2008", ] | |
o <- match(wshp@data$ISO3, z$isocode) | |
z1 <- z[o, ] | |
row.names(z1) <- wshp@data$ID | |
# 'cbind' shapefile and data.frame | |
wshp1 <- spCbind(wshp, z1) | |
head(wshp1@data) | |
# set colour | |
mypal <- c("wheat1", "red3") | |
# PPP converted GDP per capita, Geary-Khamis (G-K) method, | |
# at current prices (in International dollar). | |
v <- classIntervals(wshp1@data$cgdp, n=5, style="quantile") | |
wshp1@data$xcol <- findColours(v, mypal) | |
plot(wshp1, col = wshp1@data$xcol, lwd=1) | |
invisible(title(main="PPP converted GDP per capita - 2008, 5 Quantile", cex.main = 0.8)) | |
# | |
# FINI | |
# |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment