library(ggplot2)
library(ggthemes)
library(socviz)
library(maps)
library(mapproj)
library(viridis)Lab 7.1
Subway and Poplulation overlay
head(as_tibble(ca_pop))# A tibble: 6 × 6
GEOID NAME variable estimate moe geometry
<chr> <chr> <chr> <dbl> <dbl> <MULTIPOLYGON [°]>
1 06037 Los Angeles County, C… B01003_… 9936690 NA (((-118.6044 33.47855, -…
2 06097 Sonoma County, Califo… B01003_… 488436 NA (((-123.5335 38.76841, -…
3 06001 Alameda County, Calif… B01003_… 1663823 NA (((-122.3423 37.80556, -…
4 06045 Mendocino County, Cal… B01003_… 91145 NA (((-124.0233 40.00128, -…
5 06015 Del Norte County, Cal… B01003_… 27462 NA (((-124.2175 41.95081, -…
6 06055 Napa County, Californ… B01003_… 137384 NA (((-122.6466 38.59911, -…
Population Percentiles
library(sf)
library(leaflet)
MapPalette <- colorQuantile(palette = "viridis", domain = ca_pop$estimate, n = 20)
ca_pop %>%
st_transform(crs = "+proj=longlat +datum=WGS84") %>%
leaflet(width = "100%", height = 500) %>%
addProviderTiles(provider = "Esri.WorldImagery") %>%
addPolygons(popup = ~NAME,
stroke = TRUE,
color = "gray",
weight = 1,
smoothFactor = 0,
fillOpacity = 0.6,
fillColor = ~MapPalette(estimate)) %>%
addLegend("bottomright",
pal = MapPalette,
values = ~estimate,
title = "Population Percentiles",
opacity = 1) Here we can see the state of California and all of its counties. This map shows the population percentiles in each county. The counties that have the bigger cities like Los Angeles, San Diego, and San Francisco all have huge populations. Up in the north there is a lot of purple which indicates that many people do not live in those areas.
All the Subway Locations in California
subway <- read.csv("https://query.data.world/s/qsbvt2zetxrzn7mswkxklbsi6sbsgs?dws=00000", header=TRUE, stringsAsFactors=FALSE);
head(subway) name url
1 Subway http://order.subway.com/Stores/Redirect.aspx?s=30061&sa=0&f=c
2 Subway http://order.subway.com/Stores/Redirect.aspx?s=36022&sa=0&f=c
3 Subway http://order.subway.com/Stores/Redirect.aspx?s=43173&sa=0&f=c
4 Subway http://order.subway.com/Stores/Redirect.aspx?s=49618&sa=0&f=c
5 Subway http://order.subway.com/Stores/Redirect.aspx?s=12953&sa=0&f=c
6 Subway http://order.subway.com/Stores/Redirect.aspx?s=57011&sa=0&f=c
street_address city state zip_code
1 1800 Duke St, Ste 100 Alexandria VA 22314
2 1512 King St, Alexandria VA 22301
3 2361 Eisenhower Ave, Alexandria VA 22314
4 320 King Street, 1st Floor Alexandria VA 22314
5 5836 N. Kings Hwy, Suite A, Huntington Station Alexandria VA 22303
6 101 Independence Ave S. E., Library of Congress Washington DC 20540
country phone_number_1 phone_number_2 fax_1 fax_2 email_1 email_2 website
1 USA NA NA NA NA NA NA NA
2 USA NA NA NA NA NA NA NA
3 USA NA NA NA NA NA NA NA
4 USA NA NA NA NA NA NA NA
5 USA NA NA NA NA NA NA NA
6 USA NA NA NA NA NA NA NA
open_hours
1 Monday 7:00 AM - 7:00 PM, Tuesday 7:00 AM - 7:00 PM, Wednesday 7:00 AM - 7:00 PM, Thursday 7:00 AM - 7:00 PM, Friday 7:00 AM - 7:00 PM, Saturday 8:00 AM - 5:00 PM
2 Sunday 9:00 AM - 8:00 PM, Monday 7:00 AM - 9:00 PM, Tuesday 7:00 AM - 9:00 PM, Wednesday 7:00 AM - 9:00 PM, Thursday 7:00 AM - 9:00 PM, Friday 7:00 AM - 9:00 PM, Saturday 8:00 AM - 8:00 PM
3 Sunday 9:00 AM - 8:30 PM, Monday 6:30 AM - 9:00 PM, Tuesday 6:30 AM - 9:00 PM, Wednesday 6:30 AM - 9:00 PM, Thursday 6:30 AM - 9:00 PM, Friday 6:30 AM - 9:30 PM, Saturday 8:00 AM - 9:30 PM
4 Sunday 9:00 AM - 8:00 PM, Monday 7:00 AM - 9:00 PM, Tuesday 7:00 AM - 9:00 PM, Wednesday 7:00 AM - 9:00 PM, Thursday 7:00 AM - 9:00 PM, Friday 7:00 AM - 9:00 PM, Saturday 8:00 AM - 9:00 PM
5 Sunday 9:00 AM - 9:00 PM, Monday 7:00 AM - 10:00 PM, Tuesday 7:00 AM - 10:00 PM, Wednesday 7:00 AM - 10:00 PM, Thursday 7:00 AM - 10:00 PM, Friday 7:00 AM - 10:00 PM, Saturday 8:00 AM - 10:00 PM
6 Monday 10:00 AM - 4:00 PM, Tuesday 10:00 AM - 4:00 PM, Wednesday 10:00 AM - 4:00 PM, Thursday 10:00 AM - 4:00 PM, Friday 10:00 AM - 4:00 PM
latitude longitude facebook twitter instagram pinterest youtube
1 38.8043 -77.0611 NA NA NA NA NA
2 38.8062 -77.0565 NA NA NA NA NA
3 38.8012 -77.0691 NA NA NA NA NA
4 38.8045 -77.0433 NA NA NA NA NA
5 38.7903 -77.0769 NA NA NA NA NA
6 38.8871 -77.0041 NA NA NA NA NA
subw <- subway %>% filter(state=="CA")
subw %>% leaflet(width = "100%") %>%
addTiles() %>%
addMarkers(lat = ~latitude,
lng = ~longitude,
popup = subw$name)Combination of Population and Subway Locations
MapPalette <- colorQuantile(palette = "viridis", domain = ca_pop$estimate, n = 20)
ca_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 = subw,
lat = subw$latitude,
lng = subw$longitude,
popup = subw$name,
weight = 1,
radius=4,
color = "red",
opacity = 1)This maps combines the population percentiles with all the subway locations in the state of California. The more dense the population the more subways there seem to be. All the cities have big clusters of subways in the area.