library(leaflet)
library(data.table)
library(dplyr)
url <- "https://raw.githubusercontent.com/chrismeller/StarbucksLocations/master/stores.csv"
starbucks <- fread(url)
starbucks %>%
names()
[1] "Id" "StarbucksId" "Name"
[4] "BrandName" "StoreNumber" "PhoneNumber"
[7] "OwnershipType" "Street1" "Street2"
[10] "Street3" "City" "CountrySubdivisionCode"
[13] "CountryCode" "PostalCode" "Longitude"
[16] "Latitude" "TimezoneOffset" "TimezoneId"
[19] "TimezoneOlsonId" "FirstSeen" "LastSeen"
Since I’m only plotting starbucks locations in the US, I will be filtering the data based on the country. Also, I only require the name, longitude and latitude, so I’ll be using dplyr to select the columns, and then rename the lat and long columns.
sb_loc <- starbucks %>%
filter(CountryCode == "US") %>%
select(Latitude, Longitude, Name) %>%
rename(lat = Latitude, lng = Longitude)
# names(starbucks_latlong)
m <- leaflet(sb_loc) %>%
addProviderTiles(providers$Esri.NatGeoWorldMap) %>%
addCircleMarkers(
~ lng,
~ lat,
popup = sb_loc$Name,
weight = 3,
radius = 4,
stroke = F,
fillOpacity = 0.5,
clusterOptions = markerClusterOptions()
)
m
From our beautiful map we can see most Starbucks coffee places are at California and New York.