Learn R Programming

leafletR (version 0.1-2)

styleCat: Categorized styling

Description

Creates a categorized style based on an attribute

Usage

styleCat(prop, val, style.par, style.val, leg, ...)
cats(prop, val, style.par, style.val, leg, ...)

Arguments

prop
Property (attribute) of the data to be styled, as string.
val
A vector giving the data values to be used as categories.
style.par
Styling parameter as string. One of "col" (categorized color) or "rad" (categorized radius). Categorized radius can only be applied to points.
style.val
Styling values, a vector of colors or radii applied to the categories given by val. See details for unspecified data values.
leg
Legend title as string. The line break sequence \n may be used for line splitting.
...
Additional styling parameters, see styleSingle for details.

Value

  • A categorized style object.

encoding

UTF-8

Details

If val does not cover all data values, the unspecified data values are colored gray. By adding an extra color for unspecified data values to style.val, an "other"-category is shown in the legend.

See Also

styleSingle, styleGrad, leaflet

Examples

Run this code
# prepare data
dat <- toGeoJSON(data=system.file(package="leafletR", "files", 
  "park_sk.zip"), dest=tempdir())
data(quakes)
qks <- toGeoJSON(data=quakes, dest=tempdir())

# simple categorizing
sty <- styleCat(prop="lynx", val=c("yes", "no"), 
  style.val=c("green", "red"), leg="Lynx occurrence")
map <- leaflet(data=dat, dest=tempdir(), title="Lynx", 
  style=sty)
browseURL(map)

# just one category
sty <- styleCat(prop="wisent", val="yes", style.val="red", 
  leg="Wisent occurrence")
map <- leaflet(data=dat, dest=tempdir(), title="Wisent", 
  style=sty)
browseURL(map)

# get nice colors using ColorBrewer
require(RColorBrewer)
pal <- brewer.pal(7, "Dark2")
sty <- styleCat(prop="year", val=c("1949", "1967", "1978", "1988", 
  "1997", "1998", "2002"), style.val=pal, leg="established:\n")
map <- leaflet(data=dat, dest=tempdir(), 
  title="National parks", style=sty)
browseURL(map)

# add 'other'-category to legend
require(RColorBrewer)
pal <- brewer.pal(7, "Dark2")
sty <- styleCat(prop="year", val=c("1997", "1998", "2002"), 
  style.val=pal, leg="established:\n")
map <- leaflet(data=dat, dest=tempdir(), 
  title="National parks", style=sty)
browseURL(map)

# additional styling parameters
sty <- styleCat(prop="brown_bear", val=c("yes", "no"), 
  style.val=c("darkgreen", "red"), leg="Brown bear\noccurrence", 
  alpha=1, lwd=4, fill=NA)
map <- leaflet(data=dat, dest=tempdir(), title="Brown bear", 
  style=sty)
browseURL(map)

Run the code above in your browser using DataLab