ol_scale_fill_discrete: Fill Color Scale (Discrete)

View source: R/scales.R

ol_scale_fill_discreteR Documentation

Fill Color Scale (Discrete)

Description

Specify a discrete fill color mapping scale.

Usage

ol_scale_fill_discrete(color.vector = NULL, name = NULL,
  na.col.val = "#FFFFFF00", ordered.values = NULL,
  ordinal.scale = FALSE, opacity = 1, preserve.opacity = FALSE,
  draw.lines = NULL, draw.color = "black", draw.lty = "solid",
  draw.lwd = 1, display = FALSE)

Arguments

color.vector

character named vector of the form c(value=color). If NULL, a default color mapping is assigned.

name

character the scale name.

na.col.val

character the color assigned to unrecognized or NA values.

ordered.values

character, numeric, or factor vector containing the ordered unique discrete variable values. This input is used to determine the order of the values appearing in the legend. If not supplied, the order is taken from names(color.vector).

ordinal.scale

logical. If TRUE, the colors in the legend will not have spaces between them.

opacity

numeric in [0,1]. The fill opacity, if not specified in the color.vector colors.

preserve.opacity

logical indicating whether to draw the legend with the same opacity as the feature fills on the map.

draw.lines

logical indicating whether to draw a border around each color in the legend. If NULL, a default is assigned according to the type of layer containing the scale.

draw.color

character color of the border in the legend.

draw.lty

character indicating the border line type for the legend only. This will be passed to an R plot command. See par.

draw.lwd

numeric width of border only used in drawing the legend.

display

logical indicating whether to draw the scale for output in the HTML. If TRUE, a bitmap will be created and sourced in the HTML in an img tag. If FALSE, the draw.* inputs are ignored.

Details

This method maps OpenLayers feature fill colors to discrete variable values. This scale can be added to an Ol.Map S3 object only if the Ol.Map object has a layer with a "fill" mapping to a numeric, character, or factor type variable. If no such layer exists, attempts to add this type of scale will result in a warning. The color.vector input enables the user to specify the exact mapping, assigning colors to specific variable values.

Value

list of class Scale.Fill.Discrete.

See Also

ol_map, ol_geom_polygon, ol_geom_circle

Examples

polygon.matrix1 <- matrix(
    c(
        -80.385+c(0,0.05,0.05,0,0),
        25.782618+c(0,0,0.05,0.05,0)
    ),
    ncol=2
)
polygon.matrix2 <- matrix(
    c(
        -80.34+c(0,0.05,0.025,0),
        25.73++c(0,0,0.025*sqrt(3),0)
    ),
    ncol=2
)
polygon.list<-list(polygon.matrix1,polygon.matrix2)
polygon.df <- data.frame(shape=c("rectangle","triangle"),no=runif(2))
miami.OSM.basemap <- ol_map(
    center=c(-80.385790,25.782618),
    zoom=9
    ) + 
   streetmap() 
polygon.layer <- ol_geom_polygon(
    polygon.list,
    mapping=ol_aes(
        fill=shape #discrete mapping
    ),
    df=polygon.df,
    lwd=1,
    name="Miami Polygons",
    toggle.control=TRUE
)
polygon.fill.scale <- ol_scale_fill_discrete(
    color.vector=c(
        rectangle = 'red',
        triangle = 'blue'
    ),
    name = "Shape",
    opacity = 0.5,
    preserve.opacity = FALSE,
    display = TRUE
)
polygons.over.miami <- miami.OSM.basemap + 
    polygon.layer + 
    polygon.fill.scale

## Not run: 
# Output to file and view
ol_map2HTML(
  polygons.over.miami,
  'miami_polygons.html',
  map.heading="Miami Shapes",
  map.note="Note: Mouseover popup values are 
    independent of shape size &amp; color."
)
browseURL("miami_polygons.html")

## End(Not run)

cemarks/ROpenLayers documentation built on March 31, 2022, 12:05 p.m.