Introduction

The second part of this lab asked for an interactive map to be produced. This report will focus on the development of an interactive map that highlights the distribution Starbucks coffee shops and their ownership type along the west coast. Featuring 4 of the top 10 Food & Wine cities for coffee, this region of the US has a love for the beverage with a high concentration of coffee shops.

Package and Data Prep

First the packages are called using library().

# load packages ----

library(here)
library(leaflet)
library(sf)
library(tidyverse)
library(USAboundaries)
library(leafpop)
library(dataRetrieval)
library(leafem)
library(mapview)

Next, Starbucks directory data is imported and the data is wrangled utilizing filter() to select the West Coast states of California, Oregon , and Washington. The data table is further reduced to only information of interest to a user of the map such as the store name, phone number, address, and ownership type.

# read in starbucks location data

starbucks <- read_csv(here("data", "directory.csv")) %>%
    
# filter for west coast and wrangle data
  filter(`State/Province` %in% c("WA", "OR", "CA")) %>%
  st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326) %>%
  select(store_name = `Store Name`, 
         phone = `Phone Number`, 
         address = `Street Address`, 
         city = City, 
         state = `State/Province`, 
         owner_type = `Ownership Type`, 
         brand = Brand)

Palette

A palette is created utilizing colorFactor() to create a color-blind friendly attribute to distinguish ownership type between Company Owned and Licensed shops.

# create a palette for ownership type

pal <- colorFactor(c("#1b9e77", "#7570b3"),
                   domain = c("Company Owned", "Licensed"))

Interactive Map

Finally, the interactive map (Figure 4) is produced with a dark themed CartoDB basemap to emphasize the ownership type and store locations. A pop-up table provides the store name, phone number, and address upon clicking on a store of interest. Higher populated areas appear to show a greater concentration of stores with a majority of the stores being company owned.

# map the starbucks locations with ownership

leaflet(data = starbucks) %>%
  addProviderTiles(providers$CartoDB.DarkMatter) |> 
  addCircleMarkers(radius = 5,
                   color = ~pal(owner_type), 
                   fillOpacity = 0.9,
                   stroke = FALSE,
                   label = ~ store_name,
                   popup = leafpop::popupTable(st_drop_geometry(starbucks[,1:5]), 
                                               feature.id = FALSE, 
                                               row.numbers = FALSE)) %>%
  addLegend(pal = pal,
            values = ~owner_type,
            opacity = 0.9,
            title = "Ownership Type")

Figure 4 - An interactive map of West Coast Starbucks Store Locations with Ownership Type. A pop-up table featuring the store name, phone number, and address can be seen when clicking on a store of interest. Higher populated areas appear to show a greater concentration of stores with a majority of the stores being company owned.