Lab 7.1

Author

Elsie Sorrell

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

census_api_key("9595e84f199a4490d04d8f6a2e89f64b40cd7c39")

Looking at the Illinois counties

options(tigris_use_cache = TRUE)
IL_pop <- 
  get_acs(geography = "county",
          variables = "B01003_001",
          state = "IL",
          geometry = TRUE)

Creating a Map of Illinois Counties

MapPalette <- colorQuantile(palette = "plasma", domain = IL_pop$estimate, n = 20)

library(sf)
IL_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) 

Comments

This map shows that in the southern part of the state there is less population. Near Lake Michigan is where the higher populated counties are.

Loading Wendy’s Restaurants Locations
wendys <- read.csv("wendys_restaurants.csv")

head(wendys)
  storeId                         name                     address1
1      60                   S. BUFFORD          3383 S. BUFORD HWY.
2    8567 4201 NORTH CORRINGTON AVENUE 4201 NORTH CORRINGTON AVENUE
3     523        3206 NW TAMIAMI TRAIL      3206 N.W. TAMIAMI TRAIL
4    2210                      MANGHAM           9537 MANGHAM DRIVE
5    7679                   PRIEN LAKE     714 WEST PRIEN LAKE ROAD
6    2022                        MOPAC       12421 MOPAC EXPRESSWAY
                  address2 zipcode country      phone currency hasBreakfast
1        ATLANTA, GA 30329   30329      US 4046336541      USD        false
2    KANSAS CITY, MO 64117   64117      US 8164552849      USD         true
3 PORT CHARLOTTE, FL 33952   33952      US 9416270040      USD        false
4   LINCOLN HTS., OH 45215   45215      US 5137335149      USD        false
5   LAKE CHARLES, LA 70601   70601      US 3375629001      USD        false
6         AUSTIN, TX 78758   78758      US 5125962572      USD        false
  hasCokeFreestyle hasCSO hasDigitalCoupon hasHola hasLoyalty hasMCX
1            false  false            false   false      false  false
2             true  false            false   false      false  false
3             true  false            false   false      false  false
4            false  false            false   false      false  false
5             true  false            false   false      false  false
6             true  false             true   false       true  false
  hasMobileOrder hasMobilePay hasWifi isOpenLate latitude longitude
1          false         true   false       true 33.84292 -84.32806
2          false         true    true       true 39.16966 -94.49551
3          false         true    true       true 26.98459 -82.10110
4          false         true   false       true 39.23731 -84.45262
5          false         true    true       true 30.19858 -93.23194
6           true         true    true       true 30.41864 -97.70361
# Define Illinois ZIP code range
LOWER_ZIP <- 60001
UPPER_ZIP <- 62999

# Filter data for Illinois based on ZIP codes
wendys_il <- wendys[wendys$zipcode >= LOWER_ZIP & wendys$zipcode <= UPPER_ZIP, ]

# plot leaflet
wendys_il %>% leaflet(width = "100%") %>% 
             addTiles() %>% 
             setView(-89.0, 40.0, zoom = 6) %>% 
             addMarkers(lat = ~latitude, 
                                 lng = ~longitude, 
                                 popup = wendys_il$name)

Comments

As expected, there are more Wendy’s locations in the places with the most people. However, there does seem to be a good spread of Wendy’s across all of Illinois, all mostly along highways.

library(leaflet)
library(sf)

# Create a data frame for the Wendy's locations in Chicago
wendys_chicago <- data.frame(
  name = c(
    "145 S. Western Ave", "1623 W. Division St", "2053 W Lawrence", "2215 N Washtenaw Ave", 
    "2312 North Ashland", "2350 S Wabash Ave", "242 West Garfield Blvd", "2610 W Pershing", 
    "317 W Oak St", "3516 E 118th Street", "3610 N Western", "3943 N. Harlem Avenue", 
    "4100 S. Pulaski Road", "4140 W. Belmont Ave.", "4412 N Pulaski Rd", "4901 W. North Avenue", 
    "5472 N Harlem Ave", "5679 S. Archer", "5729 S. Kedzie Ave", "6324 N Western Ave", 
    "7031 South Western Ave", "758 West 117th Street", "7601 South Cicero Avenue", "8302 S Ashland", 
    "8645 South Stony Island", "8740 S. Lafayette Ave", "9843 S. Western"
  ),
  latitude = c(
    41.8788, 41.9039, 41.9681, 41.9191, 41.9234, 41.8479, 41.7944, 41.8191, 41.9000, 41.6860, 
    41.9469, 41.9482, 41.8157, 41.9386, 41.9564, 41.9115, 41.9794, 41.7928, 41.8046, 41.9957, 
    41.7579, 41.6806, 41.7491, 41.7445, 41.7433, 41.7293, 41.7343
  ),
  longitude = c(
    -87.6868, -87.6727, -87.6888, -87.6970, -87.6668, -87.6252, -87.6317, -87.7018, -87.6359, -87.5538, 
    -87.6870, -87.8060, -87.7247, -87.7211, -87.7257, -87.7700, -87.7921, -87.7980, -87.7033, -87.6882, 
    -87.6746, -87.6355, -87.7405, -87.6465, -87.5850, -87.6224, -87.6836
  )
)

wendys_colors <- c("white", "#E51837")  
wendys_palette <- colorQuantile(
  palette = wendys_colors,
  domain = IL_pop$estimate,
  n = 20  
)


IL_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 = ~wendys_palette(estimate)
  ) %>%
  addLegend(
    "bottomright",
    pal = wendys_palette,
    values = ~estimate,
    title = "Population Percentiles",
    opacity = 1
  ) %>%
  addCircleMarkers(
    data = wendys_il,
    lat = ~latitude,
    lng = ~longitude,
    popup = ~name,
    weight = 0.5,
    radius = 2,
    color = "black",
    opacity = 3
  ) %>%
  addMarkers(
    data = wendys_chicago,
    lat = ~latitude,
    lng = ~longitude,
    popup = ~name,
    label = ~name
  ) %>%
  addTiles() %>% 
             setView(-89.0, 40.0, zoom = 6.45)

Comments

I chose to make the circles black to stand out against the other colors on the map. I chose to use a Wendy’s red and white color to fit with the dataset. I also made the circles a little smaller, so the clump at the top right of Illinois looked a little more uniform. The city of Chicago and those surrounding it contains the most Wendy’s, and then there are a few scattered about the rest of the state.I highlighted the 27 Wendy’s in Chicago, because I felt that was quite an outstanding number of Wendy’s to have in an area.

EDITS

For the final map, I changed the type of map in the background. Instead of a topographical map, there is a road map. Now it is easy to see that many Wendy’s are found major highways or roads.