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

The following code will read the dataset in directly from data.world.
You may need to join data.world, but I think it works without joining. (Joining is free.)

If you’d rather download and then import, here is the location of the dataset:

https://data.world/data-hut/whataburger-restaurant-location-dataset

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

CREATE MAP FOR TEXAS LOCATIONS

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

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

After trying with different states where the restaurants Whataburguer are located, I decided to choose Texas since it is headquartered and based in San Antonio which made the state more popular among others.Throw this graphic it is also easier to see the expansion of the fast food chain.

ACQUIRE COUNTY-LEVEL POPULATION DATA FROM THE US CENSUS

Obtain your own census api key at: https://api.census.gov/data/key_signup.html
We will use the api key to directly download population data from the census.

Texas map

MapPalette <- 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 = ~ 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 = "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

# 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 = -99.1332, lat = 31.9686, zoom = 6) %>%  # Centering on Texas and adjusting zoom level
  addPolygons(popup = ~NAME,
              stroke = FALSE,
              smoothFactor = 0,
              fillOpacity = 0.8,  # Adjust the opacity here (0.8 for example)
              color = ~ custom_palette(estimate)) %>% 
  addLegend("bottomright", 
            pal = custom_palette,
            values = ~ estimate,
            title = "Population Percentiles",
            opacity = 1) %>% 
  addCircleMarkers(data = whataburgerUS, 
                   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 clearer and show the state counties better.The choice of red and yellow colors for the population percentiles reflects the intuitive association with higher and lower population density, respectively.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.