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

library(tidyverse)
library(leaflet)
starbucks <- read_csv("https://github.com/data-and-visualization/Intro2R/raw/master/data/All_Starbucks_Locations_in_the_US_-_Map.csv")

GIS Mapping

Introducing the library(leaflet) we use 4 lines of code to make an interactive map.1

Filter Data to NC

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

Make the Map

leaflet() %>% 
  addTiles() %>% 
  setView(-78.8310, 35.9867, zoom = 10) %>% 
  addMarkers(data = starbucksNC, lat = ~ Latitude, lng = ~ Longitude, popup = starbucksNC$Name)

  1. 5 Visualizations in 5 Minutes. ComputerWorld.com by Sharon Machlis

 
R We Having Fun Yet‽ -- Learning Series
Data & Visualization Services
Duke University Libraries
C bn
Shareable via Creative Commons: CC By-NC