Create Map Symbols for 'leaflet' maps
Usage
makeSymbol(
shape,
width,
height = width,
color,
fillColor = color,
opacity = 1,
fillOpacity = opacity,
label = NULL,
...
)
makeSvgUri(svg, width, height, strokeWidth)
makeSymbolIcons(
shape,
color,
fillColor = color,
opacity,
fillOpacity = opacity,
strokeWidth = 1,
width,
height = width,
label = NULL,
...
)
makeSymbolText(
text,
width,
height = width,
color = "black",
fillColor = color,
opacity = 1,
fillOpacity = opacity,
fontSize = round(min(width, height) * 0.6),
fontFamily = NULL,
...
)
makeSymbolTextIcons(
text,
color = "black",
fillColor = color,
opacity = 1,
fillOpacity = opacity,
strokeWidth = 0,
width,
height = width,
fontFamily = NULL,
...
)
addSymbols(
map,
lng,
lat,
values,
shape,
color,
fillColor = color,
opacity = 1,
fillOpacity = opacity,
strokeWidth = 1,
width = 20,
height = width,
dashArray = NULL,
label = NULL,
data = leaflet::getMapData(map),
...
)
addSymbolsSize(
map,
lng,
lat,
values,
shape,
color,
fillColor = color,
opacity = 1,
fillOpacity = opacity,
strokeWidth = 1,
baseSize = 20,
minSize = NULL,
maxSize = NULL,
data = leaflet::getMapData(map),
...
)
addText(
map,
lng,
lat,
text,
color = "black",
fillColor = color,
opacity = 1,
fillOpacity = opacity,
strokeWidth = 0,
width = 20,
height = width,
data = leaflet::getMapData(map),
...
)
addTextSize(
map,
lng,
lat,
values,
text,
color = "black",
fillColor = color,
opacity = 1,
fillOpacity = opacity,
strokeWidth = 0,
baseSize = 20,
data = leaflet::getMapData(map),
...
)
sizeNumeric(
values,
baseSize,
minSize = NULL,
maxSize = NULL,
centerPoint = mean(values, na.rm = TRUE)
)
sizeBreaks(values, breaks, baseSize, minSize = NULL, maxSize = NULL, ...)
makeSymbolsSize(
values,
shape = "rect",
color,
fillColor,
opacity = 1,
fillOpacity = opacity,
strokeWidth = 1,
baseSize,
minSize = NULL,
maxSize = NULL,
...
)Arguments
- shape
the desired shape of the symbol, See availableShapes
- width
in pixels
- height
in pixels
- color
stroke color
- fillColor
fill color
- opacity
stroke opacity
- fillOpacity
fill opacity
- label
a character vector of labels to display at the center of each symbol
- ...
arguments to pass to
svg shape tag for makeSymbol, makeSymbolIcons, makeSymbolsSize
svg text tag for makeSymbolText, makeSymbolTextIcons
addMarkers for addSymbols, addSymbolsSize, addText, addTextSize
pretty for sizeBreaks
- svg
inner svg tags for symbol
- strokeWidth
stroke width in pixels
- text
character string to render inside the svg
- fontSize
size of the text in pixels; defaults to
round(min(width, height) * 0.6)- fontFamily
optional font family for the svg text; if
NULLthe browser default is used- map
a map widget object created from 'leaflet'
- lng
a numeric vector of longitudes, or a one-sided formula of the form
~xwherexis a variable indata; by default (if not explicitly provided), it will be automatically inferred from data by looking for a column namedlng,long, orlongitude(case-insensitively)- lat
a vector of latitudes or a formula (similar to the
lngargument; the nameslatandlatitudeare used when guessing the latitude column fromdata)- values
the values used to generate shapes; can be omitted for a single type of shape
- dashArray
a string or vector/list of strings that defines the stroke dash pattern
- data
the data object from which the argument values are derived; by default, it is the
dataobject provided toleaflet()initially, but can be overridden- baseSize
re-scaling size in pixels of the mean of the values, the average value will be this exact size
- minSize
minimum size in pixels of a symbol; values that would scale below this are clamped to
minSize;baseSizemust be greater thanminSize- maxSize
maximum size in pixels of a symbol; values that would scale above this are clamped to
maxSize;baseSizemust be less thanmaxSize- centerPoint
the value used as the center of the scaling; defaults to the mean of
values; the symbol forcenterPointwill be exactlybaseSizepixels- breaks
an integer specifying the number of breaks or a numeric vector of the breaks; if a named vector then the names are used as labels.
Examples
library(leaflet)
data(quakes)
# symbol with a label centered inside
makeSymbol('circle', width = 24, color = 'black', fillColor = 'steelblue',
fillOpacity = 0.8, label = 'A')
#> [1] "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20width%3D%2226%22%20height%3D%2226%22%3E%0A%20%20%3Ccircle%20id%3D%22circle%22%20cx%3D%2213%22%20cy%3D%2213%22%20r%3D%2212%22%20stroke%3D%22black%22%20fill%3D%22steelblue%22%20stroke-opacity%3D%221%22%20fill-opacity%3D%220.8%22%3E%3C%2Fcircle%3E%0A%20%20%3Ctext%20x%3D%2250%25%22%20y%3D%2250%25%22%20dominant-baseline%3D%22central%22%20text-anchor%3D%22middle%22%20font-size%3D%2214px%22%20font-family%3D%22sans-serif%22%20fill%3D%22black%22%20stroke-width%3D%220%22%3EA%3C%2Ftext%3E%0A%3C%2Fsvg%3E"
#> attr(,"class")
#> [1] "character" "svgURI"
# map markers with per-point labels
quakes$label <- as.character(seq_len(nrow(quakes)))
leaflet(quakes[1:20, ]) %>%
addTiles() %>%
addSymbols(lat = ~lat, lng = ~long, color = 'black',
fillColor = 'steelblue', fillOpacity = 0.8,
label = ~label)
library(leaflet)
data(quakes)
quakes1 <- quakes[1:10,]
# makeSymbolText returns a single SVG data URI
makeSymbolText(text = 'A', width = 30, color = 'red')
#> [1] "data:image/svg+xml,%3Csvg%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20version%3D%221.1%22%20width%3D%2230%22%20height%3D%2230%22%3E%0A%20%20%3Ctext%20id%3D%22text%22%20x%3D%2250%25%22%20y%3D%2250%25%22%20dominant-baseline%3D%22central%22%20text-anchor%3D%22middle%22%20font-size%3D%2218px%22%20fill%3D%22red%22%20fill-opacity%3D%221%22%20stroke%3D%22red%22%20stroke-opacity%3D%221%22%20stroke-width%3D%220%22%3EA%3C%2Ftext%3E%0A%3C%2Fsvg%3E"
#> attr(,"class")
#> [1] "character" "svgURI"
# makeSymbolTextIcons builds a vector of icons
iconSet <- makeSymbolTextIcons(text = LETTERS[1:nrow(quakes1)],
width = 30, color = 'white',
fillColor = 'navy')
leaflet(quakes1) %>%
addTiles() %>%
addMarkers(lng = ~long, lat = ~lat, icon = iconSet)
# addText draws text labels at each location
leaflet(quakes1) %>%
addTiles() %>%
addText(lng = ~long, lat = ~lat,
text = ~as.character(seq_len(nrow(quakes1))),
color = 'white', fillColor = 'red', width = 30)
# addTextSize scales text by a numeric variable
leaflet(quakes1) %>%
addTiles() %>%
addTextSize(lng = ~long, lat = ~lat,
text = ~as.character(round(mag, 1)),
values = ~mag, color = 'black', fillColor = 'yellow',
baseSize = 30)
