Web map of Starbucks locations in the United States, categorized by
ownership type
load necessary R libraries
library(leaflet)
library(sf)
library(tidyverse)
library(janitor)
library(here)
read in and prepare starbucks data
(starbucks <- read_csv(here("data", "directory.csv")) %>%
clean_names() %>%
filter(country %in% c("US")) %>%
st_as_sf(coords = c("longitude", "latitude"), crs = 4326) %>%
select(store_name, phone_number, street_address, city, brand, ownership_type, store_number, state_province))
## Simple feature collection with 13608 features and 8 fields
## Geometry type: POINT
## Dimension: XY
## Bounding box: xmin: -159.46 ymin: 19.64 xmax: -68.74 ymax: 64.85
## Geodetic CRS: WGS 84
## # A tibble: 13,608 × 9
## store_name phone_number street_address city brand ownership_type
## <chr> <chr> <chr> <chr> <chr> <chr>
## 1 Safeway-Anchorage #18… 907-339-0900 5600 Debarr R… Anch… Star… Licensed
## 2 Safeway-Anchorage #26… 907-339-2800 1725 Abbott Rd Anch… Star… Licensed
## 3 Safeway - Anchorage #… 907-339-1300 1501 Huffman … Anch… Star… Licensed
## 4 100th & C St - Anchor… (907) 227-9… 320 W. 100th … Anch… Star… Company Owned
## 5 Old Seward & Diamond 907-344-4160 1005 E Dimond… Anch… Star… Company Owned
## 6 Fred Meyer - Anchorag… 907-264-9600 1000 E Northe… Anch… Star… Licensed
## 7 Safeway - Anchorage #… 907-339-5200 3101 PENLAND … Anch… Star… Licensed
## 8 ANC Main Terminal Tic… <NA> HMSHost, 500 … Anch… Star… Licensed
## 9 Tudor Rd and C Street 907-561-3141 110 W. Tudor … Anch… Star… Company Owned
## 10 Fred Meyer-Anchorage … 907-269-1700 7701 Debarr R… Anch… Star… Licensed
## # ℹ 13,598 more rows
## # ℹ 3 more variables: store_number <chr>, state_province <chr>,
## # geometry <POINT [°]>
set symbology for ownership type
ownertype <- c("Company Owned" = "blue", "Licensed" = "red")
find which states have the most Starbucks locations
stores_by_state <- starbucks %>%
st_drop_geometry() %>%
group_by(state_province) %>%
summarise(store_count = n()) %>%
arrange(-store_count)
head(stores_by_state)
## # A tibble: 6 × 2
## state_province store_count
## <chr> <int>
## 1 CA 2821
## 2 TX 1042
## 3 WA 757
## 4 FL 694
## 5 NY 645
## 6 IL 575