% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/legend.R
\name{legendSymbols}
\alias{legendSymbols}
\alias{addLegendSize}
\alias{addLegendLine}
\alias{addLegendSymbol}
\title{Add a legend for the sizing of symbols or the width of lines}
\usage{
addLegendSize(
  map,
  pal,
  values,
  title = NULL,
  labelStyle = "vertical-align: middle;",
  shape = "rect",
  orientation = c("vertical", "horizontal"),
  color,
  fillColor = color,
  strokeWidth = 1,
  opacity = 1,
  fillOpacity = opacity,
  breaks = 5,
  baseSize = 20,
  minSize = NULL,
  maxSize = NULL,
  numberFormat = function(x) {
     prettyNum(x, big.mark = ",", scientific = FALSE,
    digits = 1)
 },
  group = NULL,
  className = "info legend leaflet-control",
  stacked = FALSE,
  data = leaflet::getMapData(map),
  ...
)

addLegendLine(
  map,
  pal,
  values,
  title = NULL,
  labelStyle = "vertical-align: middle;",
  orientation = c("vertical", "horizontal"),
  width = 20,
  color,
  opacity = 1,
  fillOpacity = opacity,
  breaks = 5,
  baseSize = 10,
  minSize = NULL,
  maxSize = NULL,
  numberFormat = function(x) {
     prettyNum(x, big.mark = ",", scientific = FALSE,
    digits = 1)
 },
  group = NULL,
  className = "info legend leaflet-control",
  data = leaflet::getMapData(map),
  ...
)

addLegendSymbol(
  map,
  pal,
  values,
  title = NULL,
  labelStyle = "vertical-align: middle;",
  shape,
  orientation = c("vertical", "horizontal"),
  color,
  fillColor = color,
  strokeWidth = 1,
  opacity = 1,
  fillOpacity = opacity,
  width = 20,
  height = width,
  group = NULL,
  className = "info legend leaflet-control",
  dashArray = NULL,
  label = NULL,
  data = leaflet::getMapData(map),
  ...
)
}
\arguments{
\item{map}{a map widget object created from 'leaflet'}

\item{pal}{the color palette function, generated from \link[leaflet]{colorNumeric}}

\item{values}{the values used to generate sizes and if colorValues is not specified and
pal is given, then the values are used to generate  colors from the palette
function}

\item{title}{the legend title, pass in HTML to style}

\item{labelStyle}{character string of style argument for HTML text}

\item{shape}{the desired shape of the symbol, See \link[leaflegend]{availableShapes}}

\item{orientation}{stack the legend items vertically or horizontally}

\item{color}{the color of the legend symbols, if omitted pal is used}

\item{fillColor}{fill color of symbol}

\item{strokeWidth}{width of symbol outline}

\item{opacity}{opacity of the legend items}

\item{fillOpacity}{fill opacity of the legend items}

\item{breaks}{an integer specifying the number of breaks or a numeric vector of the breaks.
if a named vector is given, the names are used as labels}

\item{baseSize}{re-scaling size in pixels of the mean of the values, the average value will
be this exact size}

\item{minSize}{minimum size in pixels of a symbol; values that would scale below this are
clamped to \code{minSize}; \code{baseSize} must be greater than \code{minSize}}

\item{maxSize}{maximum size in pixels of a symbol; values that would scale above this are
clamped to \code{maxSize}; \code{baseSize} must be less than \code{maxSize}}

\item{numberFormat}{formatting functions for numbers that are displayed e.g. format, prettyNum}

\item{group}{group name of a leaflet layer group}

\item{className}{extra CSS class to append to the control, space separated}

\item{stacked}{If \code{TRUE}, symbols are overlayed onto each other for a more compact
size legend}

\item{data}{a data object. Currently supported objects are matrices, data
frames, spatial objects from the \pkg{sp} package
(\code{SpatialPoints}, \code{SpatialPointsDataFrame}, \code{Polygon},
\code{Polygons}, \code{SpatialPolygons}, \code{SpatialPolygonsDataFrame},
\code{Line}, \code{Lines}, \code{SpatialLines}, and
\code{SpatialLinesDataFrame}), and
spatial data frames from the \pkg{sf} package.}

\item{...}{arguments to pass to

\link[leaflet]{addControl} for addLegendSize

\link[base]{pretty} for sizeBreaks

\link[leaflegend]{makeSymbol} for makeSymbolsSize}

\item{width}{width in pixels of the lines}

\item{height}{in pixels}

\item{dashArray}{a string or vector/list of strings that defines the stroke dash pattern}

\item{label}{a character vector of labels to display at the center of each symbol}
}
\value{
an object from \link[leaflet]{addControl}
}
\description{
Add a legend for the sizing of symbols or the width of lines
}
\examples{
library(leaflet)
data("quakes")
quakes <- quakes[1:100,]
numPal <- colorNumeric('viridis', quakes$depth)
sizes <- sizeNumeric(quakes$depth, baseSize = 10)
symbols <- Map(
  makeSymbol,
  shape = 'triangle',
  color = numPal(quakes$depth),
  width = sizes,
  height = sizes
)
leaflet() \%>\%
  addTiles() \%>\%
  addMarkers(data = quakes,
             icon = icons(iconUrl = symbols),
             lat = ~lat, lng = ~long) \%>\%
  addLegendSize(
    values = quakes$depth,
    pal = numPal,
    title = 'Depth',
    labelStyle = 'margin: auto;',
    shape = c('triangle'),
    orientation = c('vertical', 'horizontal'),
    opacity = .7,
    breaks = 5)

# a wrapper for making icons is provided
sizeSymbols <-
makeSymbolsSize(
  quakes$depth,
  shape = 'cross',
  fillColor = numPal(quakes$depth),
  color = 'black',
  strokeWidth = 1,
  opacity = .8,
  fillOpacity = .5,
  baseSize = 20
)
leaflet() \%>\%
  addTiles() \%>\%
  addMarkers(data = quakes,
             icon = sizeSymbols,
             lat = ~lat, lng = ~long) \%>\%
  addLegendSize(
    values = quakes$depth,
    pal = numPal,
    title = 'Depth',
    shape = 'cross',
    orientation = 'horizontal',
    strokeWidth = 1,
    opacity = .8,
    fillOpacity = .5,
    color = 'black',
    baseSize = 20,
    breaks = 5)

# Group layers control
leaflet() \%>\%
  addTiles() \%>\%
    addLegendSize(
      values = quakes$depth,
      pal = numPal,
      title = 'Depth',
      labelStyle = 'margin: auto;',
      shape = c('triangle'),
      orientation = c('vertical', 'horizontal'),
      opacity = .7,
      breaks = 5,
      group = 'Depth') \%>\%
    addLayersControl(overlayGroups = c('Depth'))

# Polyline Legend for Size
baseSize <- 10
lineColor <- '#00000080'
pal <- colorNumeric('Reds', atlStorms2005$MinPress)
leaflet() \%>\%
  addTiles() \%>\%
  addPolylines(data = atlStorms2005,
               weight = ~sizeNumeric(values = MaxWind, baseSize = baseSize),
               color = ~pal(MinPress),
               popup = ~as.character(MaxWind)) \%>\%
  addLegendLine(values = atlStorms2005$MaxWind,
                title = 'MaxWind',
                baseSize = baseSize,
                width = 50,
                color = lineColor) \%>\%
  addLegendNumeric(pal = pal,
                   title = 'MinPress',
                   values = atlStorms2005$MinPress)

# Stacked Legends
leaflet(quakes) \%>\%
addTiles() \%>\%
  addSymbolsSize(values = ~10^(mag),
    lat = ~lat,
    lng = ~long,
    shape = 'circle',
    color = 'black',
    fillColor = 'red',
    opacity = 1,
    baseSize = 5) \%>\%
  addLegendSize(
    values = ~10^(mag),
    title = 'Magnitude',
    baseSize = 5,
    shape = 'circle',
    color = 'black',
    fillColor = 'red',
    labelStyle = 'font-size: 18px;',
    position = 'bottomleft',
    stacked = TRUE,
    breaks = 5)
    # dashed lines
leaflet() \%>\%
   addTiles() \%>\%
   addLegendSymbol(color='black', dashArray = list("none", "24"),
     shape = c("line", "line"), values = c('solid', 'dashed'),
     strokeWidth = 10, height = 20, width = 100)

#advanced shape customization, aesthetic arguments are propogated if
# vectors are equal length or of size 1
defaultShapes <- availableShapes()[["default"]]
leaflet() \%>\%
  addTiles() \%>\%
  addLegendSymbol(
    shape = defaultShapes,
    color = "black",
    fillColor =
      colorRampPalette(c("blue",  "yellow"))(length(defaultShapes)),
    width = seq(1L, length(defaultShapes), 1L) * length(defaultShapes),
    values = factor(defaultShapes, defaultShapes),
    strokeWidth = 2
  )

# label centered inside each legend symbol
leaflet() \%>\%
  addTiles() \%>\%
  addLegendSymbol(
    shape = c('circle', 'circle', 'circle'),
    color = 'black',
    fillColor = c('red', 'blue', 'green'),
    fillOpacity = 0.8,
    values = c('A', 'B', 'C'),
    label = c('A', 'B', 'C'),
    width = 24
  )
}
