library(ggplot2)
library(ggthemes)
library(socviz)
library(maps)
library(mapproj)
library(viridis)Lab 7
Subways in Arkansas
library(tidyverse)
library(tidycensus)
library(leaflet)
library(stringr)
census_api_key("91d75f2026ef71780c02dbff95f245e8c42f2f15")
AR_pop <-
get_acs(geography = "county",
variables = "B01003_001",
state = "AR",
geometry = TRUE)
|
| | 0%
|
| | 1%
|
|= | 1%
|
|= | 2%
|
|== | 2%
|
|== | 3%
|
|=== | 4%
|
|=== | 5%
|
|==== | 5%
|
|==== | 6%
|
|===== | 6%
|
|===== | 7%
|
|===== | 8%
|
|====== | 8%
|
|====== | 9%
|
|======= | 9%
|
|======= | 10%
|
|======= | 11%
|
|======== | 11%
|
|======== | 12%
|
|========= | 12%
|
|========= | 13%
|
|========== | 14%
|
|========== | 15%
|
|================ | 24%
|
|================= | 24%
|
|================== | 25%
|
|================== | 26%
|
|=================== | 27%
|
|=================== | 28%
|
|==================== | 28%
|
|==================== | 29%
|
|===================== | 30%
|
|====================== | 31%
|
|====================== | 32%
|
|======================= | 32%
|
|======================= | 33%
|
|======================== | 34%
|
|========================= | 35%
|
|========================= | 36%
|
|========================== | 37%
|
|========================== | 38%
|
|=========================== | 38%
|
|=========================== | 39%
|
|============================ | 40%
|
|============================ | 41%
|
|============================= | 41%
|
|============================= | 42%
|
|============================== | 42%
|
|============================== | 43%
|
|=============================== | 44%
|
|=============================== | 45%
|
|================================ | 45%
|
|================================ | 46%
|
|================================= | 47%
|
|================================== | 48%
|
|================================== | 49%
|
|=================================== | 50%
|
|==================================== | 51%
|
|==================================== | 52%
|
|===================================== | 52%
|
|===================================== | 53%
|
|====================================== | 54%
|
|====================================== | 55%
|
|======================================= | 56%
|
|======================================== | 57%
|
|======================================== | 58%
|
|========================================= | 58%
|
|========================================= | 59%
|
|========================================== | 60%
|
|=========================================== | 61%
|
|============================================ | 62%
|
|============================================ | 63%
|
|============================================ | 64%
|
|============================================= | 64%
|
|============================================== | 65%
|
|============================================== | 66%
|
|=============================================== | 67%
|
|=============================================== | 68%
|
|================================================ | 68%
|
|================================================ | 69%
|
|================================================= | 70%
|
|================================================= | 71%
|
|================================================== | 71%
|
|================================================== | 72%
|
|=================================================== | 73%
|
|=================================================== | 74%
|
|==================================================== | 74%
|
|==================================================== | 75%
|
|===================================================== | 75%
|
|===================================================== | 76%
|
|====================================================== | 77%
|
|======================================================= | 78%
|
|======================================================= | 79%
|
|======================================================== | 79%
|
|======================================================== | 80%
|
|================================================================= | 93%
|
|===================================================================== | 98%
|
|===================================================================== | 99%
|
|======================================================================| 100%
head(as_tibble(AR_pop))# A tibble: 6 × 6
GEOID NAME variable estimate moe geometry
<chr> <chr> <chr> <dbl> <dbl> <MULTIPOLYGON [°]>
1 05081 Little River County, … B01003_… 12024 NA (((-94.48558 33.65331, -…
2 05121 Randolph County, Arka… B01003_… 18619 NA (((-91.40687 36.49712, -…
3 05013 Calhoun County, Arkan… B01003_… 4773 NA (((-92.77672 33.53926, -…
4 05061 Howard County, Arkans… B01003_… 12779 NA (((-94.2549 34.3462, -94…
5 05099 Nevada County, Arkans… B01003_… 8292 NA (((-93.48322 33.47617, -…
6 05103 Ouachita County, Arka… B01003_… 22606 NA (((-93.11638 33.45245, -…
MapPalette <- colorQuantile(palette = "magma", domain = AR_pop$estimate, n = 20)
library(sf)
AR_pop %>%
st_transform(crs = "+proj=longlat +datum=WGS84") %>%
leaflet(width = "85%", height = 400) %>%
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) subway_locations_in_us <- read.csv("subway_locations_in_us.csv")
View(subway_locations_in_us)
subbar <- subway_locations_in_us %>% filter(state=="AR")
subbar %>% leaflet(width = "80%") %>%
addTiles() %>%
setView(-92.0, 36.0, zoom = 6.4) %>%
addMarkers(lat = ~latitude,
lng = ~longitude,
popup = subbar$name)COMBINE CHOROPLETH AND LOCATIONS – OVERLAY STARBUCKS LOCATIONS ONTO CHOROPLETH
MapPalette <- colorQuantile(palette = "viridis", domain = AR_pop$estimate, n = 20)
AR_pop %>%
st_transform(crs = "+proj=longlat +datum=WGS84") %>%
leaflet(width = "80%", height = 300) %>%
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)