library(tidyverse)
library(ggplot2)
library(ggthemes)
library(socviz)
library(maps)
library(mapproj)
library(questionr)
library(viridis)
library(leaflet)
library(tidycensus)Lab 7
WHataburger and Population Overlay - With Bonus Subway
ACQUIRE THE DATA
whataburgerUS <- read.csv("https://query.data.world/s/pw4t7oayqwq7o77fdxi232aa2ii2ae?dws=00000", header=TRUE, stringsAsFactors=FALSE)CREATE MAP FOR OKLAHOMA LOCATIONS
Map Whataburger store locations JUST FOR in OK using leaflet package.
whataburgerUS <- whataburgerUS %>% filter(state == "OK")
whataburgerUS %>% leaflet(width = "100%") %>%
addTiles() %>%
setView(-97.0, 35.5, zoom = 6) %>%
addMarkers(lat = ~latitude,
lng = ~longitude,
popup = whataburgerUS$name)ACQUIRE OKLAHOMA COUNTY-LEVEL POPULATION DATA FROM THE US CENSUS
OVERLAY WHATABURGER TO POPULATION
library(RColorBrewer)
# Define the color palette
MapPalette <- colorQuantile(palette = "Oranges", domain = ok_pop$estimate, n = 20)
ok_pop %>%
st_transform(crs = "+proj=longlat +datum=WGS84") %>%
leaflet(width = "100%", height = 500) %>%
addProviderTiles(provider = "Esri.WorldStreetMap") %>%
addPolygons(popup = ~NAME,
stroke = FALSE,
smoothFactor = 0,
fillOpacity = 0.6,
color = ~ MapPalette(estimate)) %>%
addLegend("bottomright",
pal = MapPalette,
values = ~ estimate,
title = "Population Percentiles",
opacity = 1) %>%
addCircleMarkers(data = whataburgerUS,
lat = whataburgerUS$latitude,
lng = whataburgerUS$longitude,
popup = whataburgerUS$name,
weight = 1,
radius=4,
color = "yellow",
opacity = 1)ADD ON SUBWAY LOCATIONS
subwayUS <- read.csv("https://query.data.world/s/jo4f3qzzqpidcj7qjikkl2jjtwqnh3?dws=00000", header=TRUE, stringsAsFactors=FALSE)
sbar <- subwayUS %>% filter(state=="OK")
rm(subwayUS)
ok_pop %>%
st_transform(crs = "+proj=longlat +datum=WGS84") %>%
leaflet(width = "100%", height = 500) %>%
addProviderTiles(provider = "Esri.WorldStreetMap") %>%
addPolygons(popup = ~NAME,
stroke = TRUE, # Enable stroke for the border
color = "gray", # Set border color to gray
weight = 1, # Set the thickness of the border
smoothFactor = 0,
fillOpacity = 0.6,
fillColor = ~ MapPalette(estimate)) %>%
addLegend("bottomright",
pal = MapPalette,
values = ~ estimate,
title = "Population Percentiles",
opacity = 1) %>%
addCircleMarkers(data = whataburgerUS,
lat = whataburgerUS$latitude,
lng = whataburgerUS$longitude,
popup = whataburgerUS$name,
weight = 1,
radius=4,
color = "yellow",
opacity = 1) %>%
addCircleMarkers(data = sbar,
lat = sbar$latitude,
lng = sbar$longitude,
popup = sbar$name,
weight = 1,
radius=4,
color = "brown",
opacity = 1)Subway has more predominance in Oklahoma, as seen in the graph, there are two clustered zones, and has like “legs” that expand over the highways, meaning that the most frequent choice of people when driving can possibly be subway, while Whataburger has less locations, and are concentratred in two zones as well (Oklahoma City and Tulsa), but still has less restaurants established, it seems Whataburger is more focused on selling in metropolitan areas where there is a population of 85% or above, while Subway has restaurants all over OK, and in zones where population is 25% or less, they established at least one franchise. People from Oklahoma have more preference for Subway, this can be due to different causes such as regional tastes, preferences, and cultural influences.