Set up the environment

knitr::opts_chunk$set(echo = TRUE) # Display code in the output document library(leaflet) # Load the leaflet package for map creation library(magrittr) # Load magrittr for the %>% pipe operator

Create the base map using leaflet

map <- leaflet() %>% addTiles()

Set up the custom icon for Chennai Central

chennaiCentralIcon <- makeIcon( iconUrl = “https://cdn.iconscout.com/icon/free/png-512/chennai-1-119692.png”, # URL of the icon image iconWidth = 30 * 408 / 255, # Adjust width according to image ratio iconHeight = 30, # Set fixed height iconAnchorX = 30 * 408 / 255 / 2, # Set the anchor for the X-axis (position of the marker) iconAnchorY = 30 / 2 # Set the anchor for the Y-axis (position of the marker) )

Add a marker with the custom icon and popup to the map

map <- map %>% addMarkers( lat = 13.0828, # Latitude of Chennai Central lng = 80.2753, # Longitude of Chennai Central popup = chennaiCentralPopup, # Attach the popup content icon = chennaiCentralIcon # Use the custom icon for the marker )

Display the map

map

Additional Examples

Display summary of the built-in ‘cars’ dataset

summary(cars)

Plot the pressure dataset

plot(pressure)