styleGrad: Graduated styling

Description Usage Arguments Value Author(s) See Also Examples

View source: R/styleGrad.R

Description

Creates a graduated style based on an attribute.

Usage

1
2
styleGrad(prop, breaks, closure, out, style.par, style.val, leg, ...)
grads(prop, breaks, closure, out, style.par, style.val, leg, ...)

Arguments

prop

Property (attribute) of the data to be styled, as string.

breaks

A vector giving the breakpoints between the desired classes.

closure

Specifies whether class intervals are closed on the left, i.e. >=breakpoint ("left", the default) or on the right, i.e. >breakpoint ("right").

out

Handling of data outside the edges of breaks. One of 0 (left and right-closed), 1 (left-closed, right-open), 2 (left-open, right-closed) or 3 (left and right-open). Default is 0.

style.par

Styling parameter as string. One of "col" (graduated color) or "rad" (graduated radius). Graduated radius can only be applied to points.

style.val

Styling values, a vector of colors or radii applied to the classes.

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 graduated style object.

Author(s)

Christian Graul

See Also

styleSingle, styleCat, leaflet

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
## Not run: 
# prepare data
data(quakes)
qks <- toGeoJSON(data=quakes, dest=tempdir())

# prepare style
range(quakes$mag)	# gives 4.0 and 6.4
sty <- styleGrad(prop="mag", breaks=seq(4, 6.5, by=0.5), 
  style.val=rev(heat.colors(5)), leg="Richter Magnitude")

# create map
map <- leaflet(data=qks, dest=tempdir(), 
  title="Fiji Earthquakes", style=sty)

# find class intervals and colors using the classInt package
library(classInt)
brks <- classIntervals(quakes$mag, 7)
cols <- findColours(brks, c("yellow", "red", "darkred"))
sty <- styleGrad(prop="mag", breaks=brks, style.val=cols, 
  leg="Richter Magnitude")
map <- leaflet(data=qks, dest=tempdir(), 
   title="Fiji Earthquakes", style=sty)

# intervals closed right
# note the gray points on the map: magnitude of 4 is outside the breaks
# (which are >4.0, >4.5, >5.0, >5.5, >6.0 and >6.5)
sty <- styleGrad(prop="mag", breaks=seq(4, 6.5, by=0.5), closure="right", 
  style.val=rev(heat.colors(5)), leg="Richter Magnitude")
map <- leaflet(data=qks, dest=tempdir(), 
  title="Fiji Earthquakes", style=sty)

# handle outliers
sty <- styleGrad(prop="mag", breaks=seq(5, 6.4, by=0.2), 
  out=2, style.val=c("white", rev(heat.colors(7))), leg="Richter Magnitude")
map <- leaflet(data=qks, dest=tempdir(), 
  title="Fiji Earthquakes", style=sty)

# graduated radius
sty <- styleGrad(prop="mag", breaks=seq(4, 6.5, by=0.5), style.par="rad", 
  style.val=c(2,5,9,14,20), leg="Richter Magnitude")
map <- leaflet(data=qks, dest=tempdir(), 
  title="Fiji Earthquakes", style=sty)

# additional styling parameters
peak <- toGeoJSON(data=system.file(package="leafletR", "files", 
  "peak_sk.kmz"), dest=tempdir())  # httr package required
sty <- styleGrad(prop="Name", breaks=seq(750, 2500, by=250), out=3, 
  style.val=terrain.colors(9), leg="Elevation", 
  col=NA, fill.alpha=1, rad=3)
map <- leaflet(data=peak, dest=tempdir(), title="Peak elevation", 
  base.map="mqsat", style=sty, popup="Name")

## End(Not run)

leafletR documentation built on May 2, 2019, 10:25 a.m.