Introduction

Road trips in Colorado’s mountainous area offer beautiful sights and interesting things to do, such as visiting national parks and forests. As road trips venture further west, the number and size of cities decrease as well as their number of coffee shops. Being a coffee enthusiast and being disappointed in the quality of hotel-provided coffee, I spend more time than I care to admit seeking coffee shops during road trips. This RMarkdown document maps big chain coffee shops, such as Dazbog, Dutch Brothers, Starbucks, and Ziggi’s, in preparation for a summer road trip through Colorado’s southwest.


Data Preparation

Prepare the workspace by loading numerous packages.

library(leaflet)
library(sf)
library(tidyverse)
library(leafpop)

The coffee shop data is loaded here and needs minor cleaning. The entire dataset is filtered to coffee shops located in Colorado. Four columns are retained and are renamed in the process: brand, store name, address, and city. The coffee shops shown here are actually locations of Starbucks, but random locations were altered to increase the variety of shops shown in the map. The coffee data was obtained from PSU Canvas (n.d.) and is part of Johnson’s (n.d.) training guide.

# Load data
coffee = read_csv('coffee.csv') |> 
  
  # Filter to Colorado locations only
  filter(`State/Province` == "CO") |> 
  
  # Define geometry columns and set coordinate reference system
  st_as_sf(coords = c("Longitude", "Latitude"), crs = 4326) |> 
  
  # Subset data and rename columns
  select(brand = `Brand`,
         store_name = `Store Name`, 
         address = `Street Address`, 
         city = `City`)

# View top rows of coffee data
glimpse(coffee)
## Rows: 481
## Columns: 5
## $ brand      <chr> "Dazbog", "Dazbog", "Dazbog", "Dazbog", "Dazbog", "Dazbog",…
## $ store_name <chr> "Speer & Federal - Denver", "Parker & Peoria-Aurora", "Hwy …
## $ address    <chr> "2990 North Speer Blvd, Unit 1, University Hills Mall", "31…
## $ city       <chr> "Denver", "Aurora", "Brighton", "Lafayette", "Denver", "Lon…
## $ geometry   <POINT [°]> POINT (-105.02 39.76), POINT (-104.85 39.66), POINT (…

Mapping the Results

Method: the coffee shops are mapped against Esri’s topographic map to provide the user geographic context into nearby tourist sites and elevation changes. The shops are also mapped against OpenStreetMap to visualize the road infrastructure between and surrounding the shops. These basemaps can be toggled by the user.

# Create a palette that maps coffee shops (brands) to colors
pal <- colorFactor(c("tomato3","steelblue3","springgreen4", "burlywood3"), 
                   domain = c("Dazbog", "Dutch Bros.", "Starbucks", "Ziggi's Coffee"))

# Map the coffee shops
leaflet(data = coffee) |> 
  
  # Add two basemaps for user choice
  addProviderTiles(providers$Esri.WorldTopoMap, group = "Terrain") |>
  addProviderTiles(providers$OpenStreetMap, group = "Street map") |>  
  
  # Adjust map to show entire state with a buffer to reduce overlap of map features
  fitBounds(lng1 = -109.045099, lat1 = 36.998999, # Southwest corner
            lng2 = -102.051793, lat2 = 41.002327, # Northeast corner
            options = list(padding = c(6, 6))) |>  
  
  # Symbolize coffee shops based on brand, label the city on hover, and provide location
  # information on click
  addCircleMarkers(color = ~pal(brand), 
                   fillOpacity = .75,
                   radius = 4,
                   stroke = FALSE,
                   label = paste0(coffee$city, ", CO"),
                   popup = leafpop::popupTable( 
                     st_drop_geometry(coffee),      # remove geometry column
                     feature.id = FALSE,            # remove feature ID column
                     row.numbers = FALSE)) |>      # remove row numbers
   
  # Create a legend in the lower right corner and provide a title 
   addLegend(position = "bottomright",
            pal = pal,
            values = ~brand,
            title = "Coffee Company") |>

  # Create a toggle feature for the basemaps
  addLayersControl(c("Street Map", "Terrain")) 

Results: mapping the coffee shop locations shows that there will be limited opportunities to buy coffee in southwestern Colorado. This suggests that coffee stops should be planned in advanced. As expected, coffee shops are located along major roads, in populated areas, and in areas with lower elevations. There is a noticeable lack of coffee shops in eastern Colorado (i.e., the Colorado plains) which could likely indicate that there are less tourist sites to visit.


Sources

Johnson, M. (No date). Interactive mapping in R. Introduction to Leaflet website. Accessed March 26, 2026 at https://mikejohnson51.github.io/leaflet-intro/index.html.

PSU Canvas. (No date). GEOG 588 Lab #4 Assignment. [Data]. Retrieved March 26, 2026 from https://psu.instructure.com/courses/2451238/pages/lab-number-4-assignment?module_item_id=47591657.