# The package maps is already in R. library(maps) # see more examples page 6 # https://cran.r-project.org/web/packages/maps/maps.pdf # https://github.com/tonmcg/County_Level_Election_Results_12-16/blob/master/2016_US_County_Level_Presidential_Results.csv # https://raw.githubusercontent.com/tonmcg/County_Level_Election_Results_12-16/master/2016_US_County_Level_Presidential_Results.csv df=read.csv("USCountyLevelPresidentialResults2016.csv",header = T,sep=",") dfIL=subset(df,state_abbr=="IL") dim(dfIL) # 102 11 map("county","Illinois",plot=T,fill=T,col="red") map("county","Illinois",plot=T,fill=T,col=2) # HW color the counties first in two different colors; sequence of colors; dependent on percentage of votes; number of votes mycolors=rep(2,times=102) mycolors[dfIL[,5]>=0.5]=3 map("county","Illinois",plot=T,fill=T,col=mycolors) # The following link contains presidential results for 2008, 2012, 2016. # https://github.com/tonmcg/County_Level_Election_Results_12-16 # Click on the link for results 2008-2016 to download the file; # otherwise it can be found in the coursework folder in the virtual desktop. df=read.csv("USCountyLevelPresidentialResults0816.csv") # There is no column for states but the first column is FIPS codes. # Each county in Illinois has a five digit FIPS code beginning with 17 and # ending with values between 000 and 203. # https://en.wikipedia.org/wiki/List_of_counties_in_Illinois