Created
March 25, 2013 16:31
-
-
Save mbacou/5238465 to your computer and use it in GitHub Desktop.
R: Draw and export circle maps to PDF
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
## Export circle map to PDF | |
pdf("US04Election-PopBin.pdf") | |
# Draw the USA outline | |
map('usa', fill=T, col="white", bg="darkgray") | |
# Create the colors for the states | |
col <- rep(rgb(.1,.1,.1,.2), length(counties$names)) | |
col[election$order] <- bluered(election$Bush,election$Kerry, .4, graded=F) | |
# Plot states without borders (should work with map, see help for fill | |
# argument, but cannot get it working) | |
m <- map('county', fill=T, plot=F) | |
polygon(m$x, m$y, col=col, border=NA) | |
# Draw county borders | |
map('county', col="darkgrey", add=T) | |
# Draw state borders | |
map('state', col="black", add=T, lwd=2) | |
# Color for circles | |
col <- bluered(election$Bush, election$Kerry, .6) | |
# Symbols is the easiest way to draw circles that have the right aspect ratio | |
symbols(election$x, election$y, circles=log(election$sizeR+1)*3,fg=col, bg=col, add=T, inches=F) | |
dev.off() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment