We offer a separate workshop on mapping in R. Please see our Mapping with R guide for more information.

starbucks <- read_csv("data/All_Starbucks_Locations_in_the_US_-_Map.csv")

GIS Mapping

Introducing the mapview package. The demonstration code below will use some latitude and longitude data to generate an interactive map. The basemap can be adjusted, and the final map can also be exported as an HTML file or a static file. This example is adapted from an article by Machlis.1

Filter Data to NC

starbucksNC <- starbucks  %>% 
  filter(State == "NC")

Make the Map

In this example, set the map projection to a common projection standard, WGS84, via the argument crs = 4326.)

mapview(starbucksNC, xcol = "Longitude", ycol = "Latitude", crs = 4269, grid = FALSE)

Alternative: Transform data to Spatial object

starbucksNC2 <- st_as_sf(starbucksNC, coords = c("Longitude", "Latitude"),  crs=4326)

Make the Map