Skip to content
Back to skills

Leaflet

ASecurity

R leaflet package for interactive maps. Use for creating web maps with markers, polygons, tiles, and layers.

  • 5 stars
  • 0 votes
  • 0 copies
  • 1 view
  • Added June 4, 2026
datago

Security analysis

A100/100

Scanned June 4, 2026

npx -y skills add LeoLin990405/r-analytics-skill --skill leaflet --agent claude-code

Installs into .claude/skills of the current project.

Are you the author of Leaflet?

Add the live security badge to your README. It updates with every re-scan.

Security grade badge for Leaflet
[![Security: A — Skills Directory](https://www.skillsdirectory.com/api/skills/leolin990405-leaflet/badge)](https://www.skillsdirectory.com/skills/leolin990405-leaflet)

More formats (shields.io, HTML) on the badges page. Keep it an A: scan every change in CI with Pro.

Download with Pro
SKILL.md
---
name: leaflet
description: R leaflet package for interactive maps. Use for creating web maps with markers, polygons, tiles, and layers.
---

# leaflet

Interactive web maps.

## Basic Map

```r
library(leaflet)

leaflet() %>%
  addTiles() %>%
  setView(lng = -73.9, lat = 40.7, zoom = 10)
```

## Markers

```r
# Single marker
leaflet() %>%
  addTiles() %>%
  addMarkers(lng = -73.9, lat = 40.7, popup = "NYC")

# From data
leaflet(df) %>%
  addTiles() %>%
  addMarkers(~lng, ~lat, popup = ~name)

# Circle markers
leaflet(df) %>%
  addTiles() %>%
  addCircleMarkers(
    ~lng, ~lat,
    radius = 5,
    color = "red",
    fillOpacity = 0.8,
    popup = ~name
  )

# Clustered markers
leaflet(df) %>%
  addTiles() %>%
  addMarkers(~lng, ~lat, clusterOptions = markerClusterOptions())

# Custom icons
icons <- makeIcon(iconUrl = "marker.png", iconWidth = 25, iconHeight = 41)
leaflet(df) %>%
  addTiles() %>%
  addMarkers(~lng, ~lat, icon = icons)
```

## Shapes

```r
# Circles
leaflet() %>%
  addTiles() %>%
  addCircles(lng = -73.9, lat = 40.7, radius = 500)

# Polygons (from sf)
leaflet(sf_data) %>%
  addTiles() %>%
  addPolygons(
    fillColor = ~colorQuantile("YlOrRd", value)(value),
    weight = 1,
    opacity = 1,
    color = "white",
    fillOpacity = 0.7,
    popup = ~name
  )

# Polylines
leaflet() %>%
  addTiles() %>%
  addPolylines(lng = c(-73.9, -74.0), lat = c(40.7, 40.8))

# Rectangles
leaflet() %>%
  addTiles() %>%
  addRectangles(lng1 = -74, lat1 = 40.6, lng2 = -73.8, lat2 = 40.8)
```

## Tile Providers

```r
# Default OpenStreetMap
addTiles()

# Provider tiles
addProviderTiles(providers$CartoDB.Positron)
addProviderTiles(providers$Stamen.Toner)
addProviderTiles(providers$Esri.WorldImagery)
addProviderTiles(providers$OpenTopoMap)

# Multiple layers
leaflet() %>%
  addTiles(group = "OSM") %>%
  addProviderTiles(providers$Esri.WorldImagery, group = "Satellite") %>%
  addLayersControl(baseGroups = c("OSM", "Satellite"))
```

## Legends and Controls

```r
# Legend
pal <- colorQuantile("YlOrRd", df$value)
leaflet(df) %>%
  addTiles() %>%
  addPolygons(fillColor = ~pal(value)) %>%
  addLegend(pal = pal, values = ~value, title = "Value")

# Layer control
leaflet() %>%
  addTiles() %>%
  addMarkers(data = df1, group = "Group 1") %>%
  addMarkers(data = df2, group = "Group 2") %>%
  addLayersControl(overlayGroups = c("Group 1", "Group 2"))

# Scale bar
addScaleBar(position = "bottomleft")

# Mini map
addMiniMap()
```

## Popups and Labels

```r
# Popup
addMarkers(popup = ~paste("<b>", name, "</b><br>", value))

# Label (on hover)
addMarkers(label = ~name)
addMarkers(label = ~name, labelOptions = labelOptions(noHide = TRUE))
```

## Save

```r
m <- leaflet() %>% addTiles()
htmlwidgets::saveWidget(m, "map.html")
```

Attribution

Is this your skill, or is something wrong with this listing? Request removal or report an issue. Author removals are honored within 72 hours.

Comments

Loading comments…