[R Course] Data Visualization with R: Interactive Maps, an application

Data Visualization R Courses

Learn to use the Leaflet R package that makes easy to integrate and control interactive maps.

Thierry Warin https://warin.ca/aboutme.html (HEC Montréal and CIRANO (Canada))https://www.hec.ca/en/profs/thierry.warin.html
01-28-2020

Load packages

Create your interactive map

Montreal

# Create your map widget

leaflet() %>% 
setView(lng = -73.5673, lat = 45.5017, zoom = 12) %>% 

# Add layers to your map by using layer functions to modify the map widget. 
# You can have as many or as little layers as you want

  addProviderTiles(providers$Esri.NatGeoWorldMap) %>%  # add ProviderTiles
    
  addMarkers(lng=-73.582189, lat=45.517958, popup="Nüance-R") %>% # add Markers
  
  addScaleBar() %>% # add ScaleBar
    
  addMiniMap() # add MiniMap

Leaflet provides a lot of different Tiles. You can find them here.

Melbourne

# Create custom icon to add to your layer
  
koalaIcon <- makeIcon(
  iconUrl = "koala.png",
  iconWidth = 70, iconHeight = 70,
  iconAnchorX = 22, iconAnchorY = 94
)
# Open packages

library(leaflet)
library(dplyr)

# Create Map Widget

leaflet() %>% 
  setView(lng = 144.9631, lat = -37.8136, zoom = 11) %>%  
  addProviderTiles(providers$Stamen.Watercolor) %>% # Stamen Watercolor Theme
  addMarkers(lng= 144.9632, lat= -37.8135, popup="Melbourne", icon = koalaIcon) %>% # Custom Icon 
  addScaleBar() %>% 
  addMiniMap()

And that is how you create basic interactive maps ! For more information about interactive maps, visit Leaflet

Citation

For attribution, please cite this work as

Warin (2020, Jan. 28). Thierry Warin, PhD: [R Course] Data Visualization with R: Interactive Maps, an application. Retrieved from https://warin.ca/posts/rcourse-datavisualizationwithr-interactivemaps-application/

BibTeX citation

@misc{warin2020[r,
  author = {Warin, Thierry},
  title = {Thierry Warin, PhD: [R Course] Data Visualization with R: Interactive Maps, an application},
  url = {https://warin.ca/posts/rcourse-datavisualizationwithr-interactivemaps-application/},
  year = {2020}
}