Polygonal distortion (cartograms)

I am trying to create a map in R that conveys both the form of the basic geometry (i.e. physical boundaries) and the relative importance of the object in terms of the associated value.

For concreteness, I would like to focus on reproducing (version) of the following map * (form, and not so much color, because I can not find the survey data):

enter image description here

I also do not want to worry about Alaska and Hawaii appearing under the USA, and not in their geodesically correct places.

I only until the data is combined with weights, made, for example, as follows:

1. Get polygons

library(maptools) library(data.table) #not strictly necessary but I prefer it #US states downloaded (500k resolution) from: #https://www.census.gov/geo/maps-data/data/cbf/cbf_state.html us.states<- readShapePoly("~/Desktop/cb_2014_us_state_5m.shp") setDT( us.states@data ) #for getting rid of territories, AK, HI states<-sprintf("%02d",1:59) ak.hi<-c("02","15") us.states.contig<- us.states[ us.states@data $STATEFP %in% setdiff(states,ak.hi),] #Unadorned plot plot(us.states.contig) text(coordinates(us.states.contig), us.states.contig@data [,paste0(STUSPS)], cex=.7) 

enter image description here

2. Add collegiate college data

 #scraped from government page library(rvest) #only necessary to scrape table electoral.college.url<- paste0("http://www.archives.gov/federal-register/", "electoral-college/allocation.html") electoral.college.dt<- (html(electoral.college.url) %>% html_nodes("table"))[[5]] %>% html_table() setDT(electoral.college.dt) setnames(electoral.college.dt,c("State","Votes")) #merge into geodata us.states.contig@data <- copy( us.states.contig@data )[ electoral.college.dt,electoral.votes:=i.Votes, on=c(NAME="State")] #plot, coloring each state by size states.ranked<- us.states.contig@data [,rank(electoral.votes, ties.method="first")] cols<-colorRampPalette(c("red","blue"))(51)[states.ranked] plot(us.states.contig,col=cols) 

enter image description here

This is all good and good - looking at this map, we can say which states have high and low representation in the electoral college. But what if (like in our target map) we wanted to represent another variable with a state color?

3. Add election results in 2012

 #scrape again #2012 Election Results by State election.wiki<- paste0("https://en.wikipedia.org/wiki/", "United_States_presidential_election,_2012") results<- html(election.wiki) %>% html_node(xpath='//*[@id="mw-content-text"]/div[22]/table') %>% html_table() #eliminate second header row, delete final row, # keep only the important columns results.trim<-results[2:(nrow(results)-1),c(1,4,21)] colnames(results.trim)<-c("name","pct","abbr") results.dt<-setDT(results.trim) #data idiosyncrasies, see Wiki page results.dt<-results.dt[!grepl("–",abbr)|grepl("a",abbr)] results.dt[grepl("–",abbr),abbr:=gsub("–.*","",abbr)] results.dt[,"pct":=as.numeric(gsub("%","",pct))] #merge us.states.contig@data <- copy( us.states.contig@data )[results.dt,vote.pct:=i.pct, on=c(STUSPS="abbr")] pcts< -us.states.contig@data [,vote.pct] cols<-c("red","blue")[(pcts>=50)+1L] tx.col<-c("white","black")[(cols=="red")+1L] plot(us.states.contig,col=cols) text(coordinates(us.states.contig), us.states.contig@data [,paste0(STUSPS)], col=tx.col) 

enter image description here

This last chart is at the heart of the problem. The first graph presented is far superior in the sense that we can sense from the percentage of red or blue on the map whether Republicans or Democrats won; this last map is misleading, since most republican states are also the most sparsely populated.

Is there a way to create a distorted version of this map that conveys the relative importance of each state in the electoral college? I could not find any help on the Internet, perhaps mainly because I do not know if there is a standard name for this type of chart.

* This map was found here ; I have seen similar size-distorted cards before, for example. at The Economist . It seems to be based on the work of Dr. Sam Wang is at the Princeton Electoral Consortium and was trained by Drew Thaler .

+1
r gis maptools cartogram sp
source share
1 answer

Following the advice of the accompanying @chkaiser package, I searched and finally found a way to do this in R. This blog post was a huge help, and the getcartr package was fantastic.

First get the Rcartogram and getcartr from GitHub:

 library(devtools) install_github("omegahat/Rcartogram") install_github('chrisbrunsdon/getcartr', subdir='getcartr') library(Rcartogram) library(getcartr) 

Now just plug and play:

 us.states.contig.carto <- quick.carto(us.states.contig, us.states.contig@data $electoral.votes) plot(us.states.contig.carto, col = cols) text(coordinates(us.states.contig.carto), us.states.contig@data [ , paste0(STUSPS)], col = tx.col) 

And in the same way, we have our cartogram:

cartogram

+3
source share

All Articles