LAB 7

Whataburger and Population Overlay

Author

Gabriela Chajon

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

ACQUIRE THE DATA

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

CREATING MAP FOR THE STATE LOCATIONS

whataburger_MS <- whataburgerUS %>% filter(state == "MS")

# Create a leaflet map centered on Mississippi
whataburger_MS %>% leaflet(width = "100%") %>% 
  addTiles() %>% 
  setView(lng = -89.75, lat = 32.75, zoom = 6) %>%  
  addMarkers(lat = ~latitude, 
             lng = ~longitude, 
             popup = whataburger_MS$name)

After trying with different states where the restaurants Whataburguer are located, I decided to choose Missisipi because it was very interesting to understand the little amount of restaurants in the state.

ACQUIRE COUNTY-LEVEL POPULATION DATA FROM THE US CENSUS

Misissipi map

# Filter Whataburger locations for Mississippi
whataburger_MS <- whataburgerUS %>% filter(state == "MS")

# Define a custom color palette with the desired colors
custom_palette <- colorQuantile(palette = "viridis", domain = ar_pop$estimate, n = 20)

ar_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 = ~ custom_palette(estimate)) %>% 
  addLegend("bottomright", 
            pal = custom_palette,
            values = ~ estimate,
            title = "Population Percentiles",
            opacity = 1) %>% 
  addCircleMarkers(data = whataburger_MS, 
                   lat = ~latitude,
                   lng = ~longitude,
                   popup = ~name,
                   weight = 1,
                   radius = 4,
                   color = "blue",
                   opacity = 1)

The map shows the locations of whataburguer restaurants overlaid on a population percentile map. The presence of a lot of Whataburger restaurants in urban areas suggests that these locations are strategically placed to cater to high consumer demand, driven by the dense population in these regions. In contrast, fewer restaurants in lower population density may indicate that are placed in rural areas and can highlight potential opportunities for Whataburger to expand its market presence into these less densely populated regions.

Changing colors and markers

# Filter Whataburger locations for Mississippi
whataburger_MS <- whataburgerUS %>% filter(state == "MS")

# Define a custom color palette with the desired colors and fewer percentiles
custom_palette <- colorQuantile(palette = c("orange", "yellow", "red"), domain = ar_pop$estimate, n = 10)  # Adjust the 'n' parameter

ar_pop %>% 
  st_transform(crs = "+proj=longlat +datum=WGS84") %>% 
  leaflet(width = "100%", height = 500) %>% 
  addProviderTiles(provider = "Esri.WorldStreetMap") %>%
  setView(lng = -89.75, lat = 32.75, zoom = 6) %>%  # Centering on Mississippi
  addPolygons(popup = ~NAME,
              stroke = FALSE,
              smoothFactor = 0,
              fillOpacity = 0.8,  
              color = ~ custom_palette(estimate)) %>% 
  addLegend("bottomright", 
            pal = custom_palette,
            values = ~ estimate,
            title = "Population Percentiles",
            opacity = 1) %>% 
  addCircleMarkers(data = whataburger_MS,  # Use filtered dataset for Mississippi locations
                   lat = ~latitude,  # Use ~latitude to reference the latitude column
                   lng = ~longitude,  # Use ~longitude to reference the longitude column
                   popup = ~name,  # Use ~name to reference the name column
                   weight = 1,
                   radius = 4,
                   color = "black",  # Change marker color to black
                   fillOpacity = 1,  # Make marker fully opaque
                   fillColor = "blue",  # Change marker fill color to blue
                   opacity = 1)  # Set marker opacity to 1

In this version of the map the use of blue markers and outlines for Whataburger restaurants provides clear visibility and distinction against the background map. The view is also centered in the state and show the state counties good.The choice of color red for the population percentiles reflects the association with higher population density, and the other way around. Moreover, these colors are commonly linked with fast food restaurants, as they convey a sense of attention, happiness, and hunger. The counties in the higher population percentiles show a clear correlation with the amount of restaurants that are located. This can be explained because big cities like Gulfport (in Harrison) and the capital, Jackson, are more urban areas than other counties.