Make the leaflet and tidyverse packages available. This implies that you have already installed them on your computer.
library(leaflet)
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ 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
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
Use Leaflet to display your central location, probably the address where you live.
myLong = -122.773261
myLat = 47.094986
leaflet() %>%
addTiles() %>%
addMarkers(myLong,myLat,popup = "My House")
Use Leaflet with the default tiles to display the locations in your myLocs file.
myLocs <- read_csv("~/Desktop/CSC545/myLocs.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.
myMap = myLocs %>%
leaflet() %>%
addTiles() %>%
addMarkers(popup = ~ID)
## Assuming "lon" and "lat" are longitude and latitude, respectively
myMap
Do that again with a different provider.
myMap = myLocs %>%
leaflet() %>%
addProviderTiles("Stamen") %>%
addMarkers(popup = ~ID)
## Assuming "lon" and "lat" are longitude and latitude, respectively
myMap
Do that again with another provider.
myMap = myLocs %>%
leaflet() %>%
addProviderTiles("CartoDB") %>%
addMarkers(popup = ~ID)
## Assuming "lon" and "lat" are longitude and latitude, respectively
myMap
Which provider looks best to you? No code, just write. CartoDB. It is a cloud-based mapping platform that provides more comprehensive data analysis and management capabilities.