Please indicate
Download the results of the 2000 election from the School of Public Affairs at American University in DC and create a map involving only the lower 48 states that show voter behavior at a county level. To keep things simple lets only consider George W. Bush, Al Gore, and Ralph Nader. Your write-up must include:
scale_fill_gradient2(name="", low="blue", high="red", mid="white") for the appropriate “mid” point. See the ggplot2 webpage for this command for inspiration.This function eliminates all non-alphanumeric characters and spaces and converts all text to lower case:
For the following ggplot, see how I didn’t define data nor any aesthetics in the base ggplot, but only within the respective geom’s. This is a nice trick that allows you to have different data and different aes apply to different geom’s; in this case state-level vs county-level data.
| state | b_avg | g_avg | n_avg | o_avg | sum_bg | sum_bgn |
|---|---|---|---|---|---|---|
| northdakota | 0.6257868 | 0.3093792 | 0.02632453 | 0.03851887 | 0.9351660 | 0.9614906 |
| alaska | 0.5821125 | 0.2839450 | 0.09763250 | 0.03632250 | 0.8660575 | 0.9636900 |
| nevada | 0.6380412 | 0.3040294 | 0.02682353 | 0.03110000 | 0.9420706 | 0.9688941 |
| idaho | 0.7172705 | 0.2350318 | 0.01735000 | 0.03033864 | 0.9523023 | 0.9696523 |
| wyoming | 0.7197130 | 0.2382000 | 0.01738261 | 0.02470000 | 0.9579130 | 0.9752957 |
As you can see from this map, the coasts prodominately voted democrat. The counties that voted for Bush are seen to be in the middle of the country. This also follows city lines. The counties with large cities (also the smaller of counties) voted democratic, while the more rural, larger counties, voted for Bush.
You can see from the hetero pander table that north dakota and alaska are the most heterogeneous states in the country. You can see this based off the sum_bg which sums the average proprotion of Bush voters with the average proportion of Gore voters. Here, Alaska takes first place, meaning that voters in Alaska were more likely to vote for candidates besides the democratic and republican nominee compared to voters in any other state. It is interesting, however, that when you factor in Nader (protrayed by sum_bgn), you see that North Dakota is actually the most heterogeneous with Alaska as a close second. This means that North Dakota voters were more likely compared to voters in any other state to vote for candidates besides Bush, Gore, and Nader. This is also shown true by the proportion “other” column (o_avg).
In this question, you must make an interactive “Single File” Shiny app that uses Leaflet. For all 184 census tracts in VT in the 2010 census, present information on the proportion of the population that is either
Use Social Explorer to get census data. I did a demo of this in class. If you don’t remember how or are stuck, please speak to me or get help from your peers. Do not submit copies of the same file.
There should be some mechanism in your Shiny app that allows one the user to toggle between the different ethnic groups.
Here is some starter code:
shapefile_name <- paste(getwd(), "/VT_census_tracts/tl_2015_50_tract.shp", sep="")
VT <- readOGR(shapefile_name, layer = "tl_2015_50_tract", verbose = FALSE)
census <- read.csv("Data/R11168779_SL140.csv")
hispanic <- read.csv("Data/hispanic.csv")
census <- census %>% select(Geo_NAME, Geo_TRACT, Geo_FIPS, SE_T054_001, SE_T054_002,
SE_T054_003, SE_T054_004, SE_T054_005, SE_T054_006,
SE_T054_007, SE_T054_008)
census <- mutate(census, hisp = hispanic$SE_T055_010)
# Rename columns
names(census)[4:12] <- c("tot_pop","white_pop","black_pop","nativ","asian","hawaii",
"other", "mixed", "hisp")
# proportions of each race in VT by total pop
census <- census %>%
mutate(
prop_white = white_pop/tot_pop,
prop_black = black_pop/tot_pop,
prop_nativ = nativ/tot_pop,
prop_asian = asian/tot_pop,
prop_hawaii = hawaii/tot_pop,
prop_other = other/tot_pop,
prop_mixed = mixed/tot_pop,
prop_hisp = hisp/tot_pop)
#Prop_white
leaflet(VT) %>%
addPolygons(
stroke = FALSE, fillOpacity = 0.8, smoothFactor = 0.5,
color = ~colorQuantile("Blues", census$prop_white)(census$prop_white)) %>%
addTiles() %>%
addPolylines(color="black", weight=1) %>%
addLegend("bottomright", values = ~census$prop_white,
title = "Proportion White of Total Pop",
labFormat = labelFormat(prefix = ""),
opacity = 1, pal = colorNumeric("Blues", census$prop_white))
#Mo showed me how to do this
#Prop_black
leaflet(VT) %>%
addPolygons(
stroke = FALSE, fillOpacity = 0.8, smoothFactor = 0.5,
color = ~colorQuantile("BuGn", census$prop_black)(census$prop_black)) %>%
addTiles() %>%
addPolylines(color="black", weight=1) %>%
addLegend("bottomright", values = ~census$prop_black,
title = "Proportion Black of Total Pop",
labFormat = labelFormat(prefix = ""),
opacity = 1, pal = colorNumeric("BuGn", census$prop_black))
#Prop_asian
leaflet(VT) %>%
addPolygons(
stroke = FALSE, fillOpacity = 0.8, smoothFactor = 0.5,
color = ~colorQuantile("RdPu", census$prop_asian)(census$prop_asian)) %>%
addTiles() %>%
addPolylines(color="black", weight=1) %>%
addLegend("bottomright", values = ~census$prop_asian,
title = "Proportion Asian of Total Pop",
labFormat = labelFormat(prefix = ""),
opacity = 1, pal = colorNumeric("RdPu", census$prop_asian))
#Prop_hispanic
leaflet(VT) %>%
addPolygons(
stroke = FALSE, fillOpacity = 0.8, smoothFactor = 0.5,
color = ~colorQuantile("Oranges", census$prop_hisp)(census$prop_hisp)) %>%
addTiles() %>%
addMarkers(lng=-73.2540, lat=44.1673, popup="Vergennes") %>%
addPolylines(color="black", weight=1) %>%
addLegend("bottomright", values = ~census$prop_hisp,
title = "Proportion Hispanic of Total Pop",
labFormat = labelFormat(prefix = ""),
opacity = 1, pal = colorNumeric("Oranges", census$prop_hisp))
#two or more races
leaflet(VT) %>%
addPolygons(
stroke = FALSE, fillOpacity = 0.8, smoothFactor = 0.5,
color = ~colorQuantile("Reds", census$prop_other)(census$prop_other)) %>%
addTiles() %>%
addPolylines(color="black", weight=1) %>%
addLegend("bottomright", values = ~census$prop_other,
title = "Proportion of >2 races of Total Pop",
labFormat = labelFormat(prefix = ""),
opacity = 1, pal = colorNumeric("Reds", census$prop_other))
Overall, one can see that Vermont is predominately white. That is not to say, however, that there aren’t some pockets of diversity. The Northwest corner of Vermont seems to have a lot of diversity. You can see high proportions of black people, asian, and hispanic in this region of Vermont. If you look at this region on the White proportion map, you can see that it has low proportions of white compared to the rest of Vermont. Between black, asian, hispanics, and other, you can see that blacks and asians are very similarly represented as minority ethnic groups in Vermont. The highest for both ethnicities / race is ~8-9%. Hispanics are represented much less with the census tract with largest hispanic population at ~4%. There are very few people living in Vermont who identify as having two or more races. The census tract with the largest population of people with two or more is about 1.3%. Interestingly, I know that there is a large proportion of hispanics that live in Vergennes because I have friends who work at an Open Door Clinic there. I know that they often interact with patients who only speak Spanish. The map of proportion of Hispanic people matches with this observation. If one were to zoom in at Vergennes, one can see that it has a census tract with one of the highest proportions of hispanics.