Map in R

Hello friends! today we’ll be learning how to create map in R using leaflet package in R. The reusable code as below.

Code

list.of.packages <- c("leaflet", "htmlwidgets")
new.packages <- list.of.packages[!(list.of.packages %in% installed.packages()[,"Package"])]
if(length(new.packages)) install.packages(new.packages)
library(leaflet)
my.path = 'assignment.csv'
df = read.csv(my.path)
map = leaflet() %>%
addTiles( ) %>%
addMarkers(data = df, lat = df$Latitude, lng = df$Longitude )
map
htmlwidgets::saveWidget(map, file = paste0(dirname(my.path), "/map.html"))

check my Github repository

Keep visiting Analytics Tuts for more tutorials.

Thanks for reading! Comment your suggestions and queries



Leave a Reply

Your email address will not be published. Required fields are marked *