*leaflet is one of R package that is used to create dynamic maps.It is most popular open source java script library for interactive mobile-friendly maps.
*This package makes it easy to integrate and control leaflet maps in R.
*leaflet package is used by leading technology companies like Git Hub, pinterest, USA today, Washington post, Foursquare, GIS specialist, Map box …
*leaflet example: NAtional park service use leaflet to create an interactive map
FEATURES
*Easily render spatial objects from the sp or sf packages, or data frames with latitude/longitude columns.
*Create map from R studio.
*leaflet maps can easily be integrated with in R Markdown and R shinny apps.
*Display maps in non spherical mercator projections.
INSTTALL PACKAGE
TO INSTALL THIS R PACKAGE WE HAVE TO RUN THE FOLLOWING R PROMPT.
#install.packages("leaflet")
ONCE WE INSTALL THE PACKAGE WE CAN BE ABLE TO USE IT.
library(leaflet)
## Warning: package 'leaflet' was built under R version 4.1.3
library("tidyverse")
## -- Attaching packages --------------------------------------- tidyverse 1.3.1 --
## v ggplot2 3.3.5 v purrr 0.3.4
## v tibble 3.1.2 v dplyr 1.0.7
## v tidyr 1.1.3 v stringr 1.4.0
## v readr 1.4.0 v forcats 0.5.1
## Warning: package 'dplyr' was built under R version 4.1.1
## -- Conflicts ------------------------------------------ tidyverse_conflicts() --
## x dplyr::filter() masks stats::filter()
## x dplyr::lag() masks stats::lag()
library("pander")
one of the usage of leaflet is to create map using Tiles.
library(leaflet)
my_map <- leaflet() %>%
addTiles()
my_map
we can add rectangle on our map to show some specific area.
By running the following code we can see how :
leaflet() %>%
addTiles() %>%
addRectangles(lat1 = 37.3858 ,
lng1 = -122.0595, lat2 = 37.3890,
lng2 = -122.0625)
Base Map
Leaflet supports basemap using map tiles, popularized by Google Maps and now used by all interactive web maps.
m <- leaflet() %>%
setView(lng = -71.0589, lat = 42.3601, zoom = 12)
m %>% addTiles()
Further Resource
work site
https://rstudio.github.io/leaflet/colors.html
https://bookdown.org/nicohahn/making_maps_with_r5/docs/leaflet.html