DAT-4313 - LAB 7

Whataburger and Arizona Population Overlay - With Bonus Subway

Author

ANDREA DAVILA

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

ACQUIRE THE DATA

Here is the location of the dataset:
https://data.world/data-hut/whataburger-restaurant-location-dataset

whataburgerUS <- read.csv("https://query.data.world/s/6ubwqcbx4mxeijvzpcewa4htogxmje?dws=00000", header=TRUE, stringsAsFactors=FALSE)

CREATE MAP FOR ARIZONA LOCATIONS

Map Whataburger store locations JUST FOR in AZ using leaflet package.

whataburgerUS <- whataburgerUS %>% filter(state == "AZ")


whataburgerUS %>% leaflet(width = "100%") %>% 
             addTiles() %>% 
             setView(-111.0, 34.0, zoom = 6) %>%
             addMarkers(lat = ~latitude, 
                                 lng = ~longitude, 
                                 popup = whataburgerUS$name)

ACQUIRE ARIZONA COUNTY-LEVEL POPULATION DATA FROM THE US CENSUS

Obtain your own census api key at: https://api.census.gov/data/key_signup.html

OVERLAY WHATABURGER TO POPULATION

MapPalette <- colorQuantile(palette = c("yellow", "orange", "red"), domain = az_pop$estimate, n = 20)

az_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,
              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 = "white", 
                   opacity = 1)

ADD ON SUBWAY LOCATIONS

subwayUS <- read.csv("https://query.data.world/s/2tq6wudzqth5irte42knv4375r5rf3?dws=00000", header=TRUE, stringsAsFactors=FALSE)

sbar <- subwayUS %>% filter(state=="AZ")

rm(subwayUS)


az_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 = sbar, 
                   lat = sbar$latitude,
                   lng = sbar$longitude,
                   popup = sbar$name,
                   weight = 1,
                   radius=4,
                   color = "black", 
                   opacity = 1) %>% 
  addCircleMarkers(data = whataburgerUS, 
                   lat = whataburgerUS$latitude,
                   lng = whataburgerUS$longitude,
                   popup = whataburgerUS$name,
                   weight = 1,
                   radius=4,
                   color = "white", 
                   opacity = 1)

INTERPRETATIONS

With the result of these three maps we can see that there is correlation between the three of them. First with the population percentages and the largest cities. The sections that are the darkest shade of red are where Phoenix, Tucson and Mesa are, the three most populated cities in Arizona. Secondly, in connection with this, we can see the majority of Whataburger restaurants are located in the three largest cities in the state or nearby. In fact, there are no other restaurants in cities other than these. With this we can see that Arizona is not a state with many Whataburger restaurants, compared to other states in the country and other fast food restaurants. On the other hand, Subway is a fast food restaurant that does have a large number of restaurants all over the state.

END