I am comparing results of the 2010 and 2014 mid-term elections in the state of Virginia. I am doing this by using a file that has the Virginian congressional districts over the map of Virginia. I want to color the districts that elected a Republican canidate red and color the districts that elected a Democratic canidate blue.
There is more to the project but once I figure out how to do this one thing I will be able to figure out how I will go about the rest of the project.
I am using the files found here:
http://www.arcgis.com/home/item.html?id=dc20260d27654c64bfa0c2979a317597
This is the code I am using to plot the shapefile:
library(maptools)
library(shapefiles)
CCBound <- readShapePoly("tl_rd13_51_cd113")
CCBound2 <- CCBound
system.time(plot(CCBound2))
This gives me a nice map of Virginia with the ten congressional districts outlined.
How should I go about coloring in the districts as I stated above?
Here's a
ggplot
solution. You seem to be asking for a base R method, but IMO it's worthwhile to learn ggplot for the added flexibility. This should get you started.I had to make some assumptions about the format of your data, since you didn't provide it. The code below is just shows how the data is organized in this example
This plots the maps.
Note that in 2014 in the 3rd District the Democrat ran unopposed, while the 6th and 9th Districts were contested, but there was no Democrat running.
The posts here, and here have a explanation of the workflow.