Learn R Programming

⚠️There's a newer version (1.2.1) of this package.Take me there.

leaflegend

This package provides extensions to the leaflet package to customize leaflet legends without adding an outside css file to the output to style legends. The legend extensions allow the user to add images to legends, style the labels of the legend items, change orientation of the legend items, use different symbologies, and style axis ticks. Syntax and style is consistent with the leaflet package.

Installation

You can install the released version of leaflegend from CRAN with:

install.packages("leaflegend")

Install the development version with:

devtools::install_github("tomroh/leaflegend")

Example

Use addLegend*() to create easily customizable legends for leaflet.

library(leaflegend)
library(leaflet)
data(quakes)
quakes[['group']] <- sample(c('A', 'B', 'C'), nrow(quakes), replace = TRUE)
factorPal <- colorFactor('Dark2', quakes$group)
leaflet() %>%
  addTiles() %>%
  addCircleMarkers(
    data = quakes,
    lat = ~ lat,
    lng = ~ long,
    color = ~ factorPal(group),
    opacity = 1,
    fillOpacity = 1
  ) %>%
  addLegendFactor(
    pal = factorPal,
    title = htmltools::tags$div('addLegendFactor', style = 'font-size: 24px; color: red;'),
    labelStyle = 'font-size: 18px; font-weight: bold;',
    orientation = 'horizontal',
    values = quakes$group,
    position = 'topright',
    shape = 'triangle',
    width = 30,
    height = 30
  )

Copy Link

Version

Install

install.packages('leaflegend')

Monthly Downloads

23,110

Version

0.3.0

License

MIT + file LICENSE

Issues

Pull Requests

Stars

Forks

Maintainer

Thomas Roh

Last Published

May 21st, 2021

Functions in leaflegend (0.3.0)

addLegendImage

Add a Legend with Images
makeSymbol

Create an SVG tag for the symbol
addLeafLegends

Add Customizable Color Legends to a 'leaflet' map widget
addLegendSize

Add a legend that for the sizing of symbols