addLegendSize: Add a legend that for the sizing of symbols or the width of...

Description Usage Arguments Value Examples

View source: R/legend.R

Description

Add a legend that for the sizing of symbols or the width of lines

Usage

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
addLegendSize(
  map,
  pal,
  values,
  title = NULL,
  labelStyle = "",
  shape = c("rect", "circle", "triangle", "plus", "cross", "diamond", "star",
    "stadium"),
  orientation = c("vertical", "horizontal"),
  color,
  fillColor,
  strokeWidth = 1,
  opacity = 1,
  fillOpacity = opacity,
  breaks = 5,
  baseSize = 10,
  numberFormat = function(x) {     prettyNum(x, big.mark = ",", scientific = FALSE,
    digits = 1) },
  group = NULL,
  className = "info legend leaflet-control",
  ...
)

sizeNumeric(values, baseSize)

sizeBreaks(values, breaks, baseSize, ...)

makeSizeIcons(
  values,
  shape = c("rect", "circle", "triangle", "plus", "cross", "diamond", "star",
    "stadium"),
  pal,
  color,
  colorValues,
  fillColor,
  opacity,
  fillOpacity = opacity,
  strokeWidth = 1,
  baseSize,
  ...
)

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

Arguments

map

a map widget object created from 'leaflet'

pal

the color palette function, generated from colorNumeric

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

title

the legend title, pass in HTML to style

labelStyle

character string of style argument for HTML text

shape

shape of the color symbols

orientation

stack the legend items vertically or horizontally

color

the color of the legend symbols, if omitted pal is used

fillColor

fill color of symbol

strokeWidth

width of symbol outline

opacity

opacity of the legend items

fillOpacity

fill opacity of the legend items

breaks

an integer specifying the number of breaks or a numeric vector of the breaks

baseSize

re-scaling size in pixels of the mean of the values, the average value will be this exact size

numberFormat

formatting functions for numbers that are displayed e.g. format, prettyNum

group

group name of a leaflet layer group

className

extra CSS class to append to the control, space separated

...

arguments to pass to

addControl for addLegendSize

pretty for sizeBreaks

makeSymbol for makeSizeIcons

colorValues

the values used to generate color from the palette function

width

width in pixels of the lines

Value

an object from addControl

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
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 <-
makeSizeIcons(
  quakes$depth,
  shape = 'cross',
  pal = numPal,
  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)

leaflegend documentation built on Jan. 17, 2022, 5:07 p.m.