all_states <- map_data("state")
congress<-read_csv("womenincongress.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_double(),
## state = col_character(),
## senators = col_double(),
## representatives = col_double(),
## total = col_double()
## )
names(congress)[2] <- "region"
stateData <- left_join(all_states,congress,by="region")
senatePlot <- ggplot()+geom_polygon(data=stateData,aes(x=long, y=lat, group = group, fill=senators),color="grey50")+coord_map()
reProp<- summarize(group_by(congress,region),reProp=representatives/total)
reProp <- full_join(reProp, all_states, by="region")
housePlot <- ggplot()+geom_polygon(data=reProp, aes(x=long, y=lat, group = group, fill=reProp), color="grey50")+coord_map()+ scale_fill_gradient(name="Female Representatives",low="whitesmoke",high="darkred")+labs(x="",y="",title="Women in the House")+theme_classic()+theme(axis.ticks.y = element_blank(),axis.text.y = element_blank(), axis.ticks.x = element_blank(),axis.text.x = element_blank())
housePlot
electionData <- read_csv("2012.csv")
## Warning: Missing column names filled in: 'X1' [1]
## Parsed with column specification:
## cols(
## X1 = col_character(),
## ObamaVotes = col_double(),
## ObamaEV = col_double(),
## RomneyVotes = col_double(),
## RomneyEV = col_double(),
## JohnsonVotes = col_double(),
## JohnsonEV = col_double(),
## SteinVotes = col_double(),
## SteinEV = col_double()
## )
names(electionData)[1] <- "region"
electionData$ObamaPerc <- electionData$ObamaVotes/(electionData$ObamaVotes+electionData$RomneyVotes+electionData$JohnsonVotes+electionData$SteinVotes)
electionData$RomneyPerc <- electionData$RomneyVotes/(electionData$ObamaVotes+electionData$RomneyVotes+electionData$JohnsonVotes+electionData$SteinVotes)
electionData <- merge(all_states,electionData,by="region")
south_data <- filter(electionData, region %in% c("delaware", "florida", "georgia", "maryland", "north carolina", "south carolina", "virginia", "district of columbia", "west virginia", "alabama", "kentucky", "mississippi", "tennessee", "arkansas", "louisiana", "oklahoma", "texas"))
south_electionPlot <- ggplot()+geom_polygon(data=south_data,aes(x=long, y=lat, group = group, fill=ObamaPerc),color="grey50")+coord_map()+labs(x="",y="",title="2012 Election Results")+theme_classic()+ theme(axis.ticks.y = element_blank(),axis.text.y = element_blank(), axis.ticks.x = element_blank(),axis.text.x = element_blank()) + scale_fill_gradient2(name="Obama's Percenatage",low="red",mid="white",high="blue",midpoint=.5)
south_electionPlot