Description Usage Arguments Value Author(s) See Also Examples
Creates a graduated style based on an attribute.
1 2 |
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 ( |
out |
Handling of data outside the edges of |
style.par |
Styling parameter as string. One of |
style.val |
Styling values, a vector of colors or radii applied to the classes. |
leg |
Legend title as string. The line break sequence |
... |
Additional styling parameters, see |
A graduated style object.
Christian Graul
styleSingle
, styleCat
, leaflet
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.