Make the leaflet and tidyverse packages available. This implies that you have already installed them on your computer.
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.2.2
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.4.0 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.10
## ✔ tidyr 1.2.1 ✔ stringr 1.4.1
## ✔ readr 2.1.2 ✔ forcats 0.5.2
## Warning: package 'ggplot2' was built under R version 4.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
myLocations <- read_csv("myLocations.csv")
## Rows: 5 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (1): ID
## dbl (2): lat, lon
##
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
myLocations
## # A tibble: 5 × 3
## lat lon ID
## <dbl> <dbl> <chr>
## 1 47.0 -123. OldMain
## 2 47.0 -123. Komachin
## 3 47.0 -123. Timberline
## 4 47.0 -123. Home
## 5 47.1 -123. Costco
Use Leaflet to display your central location, probably the address where you live.
myHome <- leaflet() %>% addTiles() %>% addMarkers(lng = -122.8255, lat = 47.00977, popup = "Home")
myHome
Use Leaflet with the default tiles to display the locations in your myLocs file.
myLocationsMap <- leaflet(myLocations) %>%
addTiles() %>%
addMarkers(lng= ~lon, lat= ~lat, popup= ~ID)
myLocationsMap
Do that again with a different provider.
myLocationsMap2 <- leaflet(myLocations) %>%
addProviderTiles(providers$CartoDB.Voyager) %>%
addMarkers(lng= ~lon, lat= ~lat, popup= ~ID)
myLocationsMap2
Do that again with another provider.
myLocationsMap3 <- leaflet(myLocations) %>%
addProviderTiles(providers$Stamen.Watercolor) %>%
addMarkers(lng= ~lon, lat= ~lat, popup= ~ID)
myLocationsMap3
Which provider looks best to you? No code, just write. I like how clean and simple the defualt open street map tiles are, but the best provider is probably the CartoDB Voyager.