Lab7

Subways In Wyoming

Author

Katlyn Collins

library(ggplot2)
library(ggthemes)
library(socviz)
library(maps)
library(mapproj)
library(viridis)
library(rsconnect)
library(rmarkdown)
library(tidyverse)
library(tidycensus)
library(leaflet)

library(stringr)

census_api_key("91d75f2026ef71780c02dbff95f245e8c42f2f15")


WY_pop <- 
  get_acs(geography = "county",
          variables = "B01003_001",
          state = "WY",
          geometry = TRUE)
head(as_tibble(WY_pop))
# A tibble: 6 × 6
  GEOID NAME                   variable estimate   moe                  geometry
  <chr> <chr>                  <chr>       <dbl> <dbl>        <MULTIPOLYGON [°]>
1 56045 Weston County, Wyoming B01003_…     6870    NA (((-105.0808 43.96622, -…
2 56029 Park County, Wyoming   B01003_…    29878    NA (((-111.0546 45.00095, -…
3 56013 Fremont County, Wyomi… B01003_…    39402    NA (((-110.0532 44.00802, -…
4 56003 Big Horn County, Wyom… B01003_…    11690    NA (((-108.6218 44.99613, -…
5 56007 Carbon County, Wyoming B01003_…    14609    NA (((-107.93 41.49996, -10…
6 56035 Sublette County, Wyom… B01003_…     8801    NA (((-110.6234 42.7792, -1…
MapPalette <- colorQuantile(palette = "magma", domain = WY_pop$estimate, n = 20)

library(sf)
WY_pop %>% 
  st_transform(crs = "+proj=longlat +datum=WGS84") %>% 
  leaflet(width = "100%", height = 500) %>% 
  addProviderTiles(provider = "Esri.WorldPhysical") %>% 
  addPolygons(popup = ~NAME,
              stroke = FALSE,
              smoothFactor = 0,
              fillOpacity = 0.7,
              color = ~ MapPalette(estimate)) %>% 
  addLegend("bottomright", 
            pal = MapPalette,
            values = ~ estimate,
            title = "Population Percentiles",
            opacity = 1) 

There is one central spot in Wyoming that has a high population percentile. The outskirts of Wyoming seem to have the second biggest amount of population percentiles. The top right area of Wyoming has the smallest population percentile.

subway_locations_in_us <- read.csv("subway_locations_in_us.csv")


subbar <- subway_locations_in_us %>% filter(state=="WY")

subbar %>% leaflet(width = "100%") %>% 
             addTiles() %>% 
             setView(-108, 43, zoom = 6) %>% 
             addMarkers(lat = ~latitude, 
                                 lng = ~longitude, 
                                 popup = subbar$Riverton)
The outskirts of Wyoming seem to have the main amount of subway locations. Their bigger population percentiles seem to be on the outside as well so this makes sense. They have more locations where the population is the highest.
MapPalette <- colorQuantile(palette = "magma", domain = WY_pop$estimate, n = 20)


WY_pop %>% 
  st_transform(crs = "+proj=longlat +datum=WGS84") %>% 
  leaflet(width = "100%", height = 500) %>% 
  addProviderTiles(provider = "Esri.WorldPhysical") %>% 
  addPolygons(popup = ~NAME,
              stroke = FALSE,
              smoothFactor = 0,
              fillOpacity = 0.7,
              color = ~ MapPalette(estimate)) %>% 
  addLegend("bottomright", 
            pal = MapPalette,
            values = ~ estimate,
            title = "Population Percentiles",
            opacity = 1) %>% 
addCircleMarkers(data = subbar, 
                   lat = subbar$latitude,
                   lng = subbar$longitude,
                   popup = subbar$name,
                   weight = 1,
                   radius=3,
                   color = "white", 
                   opacity = 9)

Areas in Wyoming with the highest population percentiles seem to have the largest amount of subways in their locations. They do however appear to be in clusters which means they have many locations in one area. Areas with the smallest population percentiles don’t have as many subway locations.