Skip to content

Instantly share code, notes, and snippets.

@karthik
Last active May 19, 2017 09:53
Show Gist options
  • Save karthik/cb04d9281fca01fdcb6b633d9b20c8f5 to your computer and use it in GitHub Desktop.
Save karthik/cb04d9281fca01fdcb6b633d9b20c8f5 to your computer and use it in GitHub Desktop.
library(tidyverse)
library(leaflet)
# If you don't have leaflet, install with:
# install.packages("leaflet")
# How to map data with Leaflet
download.file(
"https://commondatastorage.googleapis.com/ckannet-storage/2012-07-09T214020/global_airports.csv",
destfile = "global_airports.csv"
)
df <- read_csv("./global_airports.csv")
names(df)
leaflet(df) %>% addTiles() %>% addCircles()
# You can also pipe in bounds by adding
# %>% fitBounds(lng1, lat1, lng2, lat2)
# or adding a center to zoom into
# setView(lng, lat, zoom, options = list())
# A more complex map
leaflet(sample_frac(df, 0.01)) %>%
addProviderTiles(providers$Esri.WorldStreetMap) %>%
addCircles() %>%
addMarkers()
# Set the center of the map to London, NHM
leaflet(sample_frac(df, 0.01)) %>%
addProviderTiles(providers$Esri.WorldStreetMap) %>%
addCircles() %>%
addMarkers() %>%
setView("0.1278", "51.5074", zoom = 5)
@karthik
Copy link
Author

karthik commented May 19, 2017

Also checkout the mapr package from rOpenSci

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment