A look at the Starbucks of WIsconsin

Section 1: Data

# Load the required packages
library(dplyr)
library(sf)
library(leaflet)
library(tidyverse)
library(USA.state.boundaries)

# Load your data
directory <- read.csv("C:/PENNSTATE/GEOG588_Analytical Approaches_/R_Projects/Lab4/Data/directory.csv")

# Filter, convert to spatial data frame, and select columns
wisconsin <- directory %>%
  filter(`State.Province` == "WI") %>%
  st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326) %>% 
  select(store_name = `Store.Name`, phone = `Phone.Number`, address = `Street.Address`, city = City, brand = Brand) %>%
  mutate(Longitude = st_coordinates(geometry)[,1], 
         Latitude = st_coordinates(geometry)[,2])

Interactive Map Showing the 145 Starbucks in Wisconsin

Open Street Maps with Awsome Icons

# Create custom icons
icons <- awesomeIcons(
  icon = 'coffee', 
  markerColor = 'blue', 
  library = 'fa', 
  spin = TRUE
)

# Create the leaflet map with custom icons
leaflet(data = wisconsin) %>%
  addProviderTiles(providers$OpenStreetMap.HOT) %>% 
  addAwesomeMarkers(~Longitude, ~Latitude, icon = icons, popup = ~store_name, label = ~city)

Interactive Map Showing the 145 Starbucks Locations in Wisconsin

CLustering

# Load the required packages
library(dplyr)
library(sf)
library(leaflet)
library(tidyverse)

# Load your data
directory <- read.csv("C:/PENNSTATE/GEOG588_Analytical Approaches_/R_Projects/Lab4/Data/directory.csv")

# Filter, convert to spatial data frame, and select columns
wisconsin_Clusters <- directory %>%
  filter(`State.Province` == "WI") %>%
  st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326) %>% 
  select(store_name = `Store.Name`, phone = `Phone.Number`, address = `Street.Address`, city = City, brand = Brand) %>%
  mutate(Longitude = st_coordinates(geometry)[,1], 
         Latitude = st_coordinates(geometry)[,2])

# Create the leaflet map with clustering and normal markers
leaflet(data = wisconsin_Clusters) %>%
  addProviderTiles(providers$OpenStreetMap.HOT) %>% 
  addMarkers(
    ~Longitude, ~Latitude, 
    popup = ~store_name, 
    label = ~city, 
    clusterOptions = markerClusterOptions()
  )

Interactive Map showing the clusters of Starbucks in Wisconsin

Adding Color Ramps with Circle Markers Colors for Cities And Legend

# Create a color palette with more contrast
pal <- colorFactor(c("red", "blue", "orange", "green", "purple"), domain = unique(wisconsin_Clusters$city))

# Create the leaflet map with circle markers and a legend
leaflet(data = wisconsin_Clusters) %>%
  addProviderTiles(providers$CartoDB.Positron) %>%
  addCircleMarkers(
    color = ~pal(city), 
    fillOpacity = .5, 
    stroke = FALSE,
    popup = ~store_name,
    label = ~city
  ) %>%
  addLegend(
    "bottomright", 
    pal = pal, 
    values = ~city, 
    title = "City", 
    opacity = 1)

Map Using circles that are color coded based on the cities that where Starbucks are Located