Learn R Programming

ggincerta (version 0.1.0)

ScaleBivariate: Bivariate color scales

Description

scale_*_bivariate creates a bivariate palette by mixing two colour ramps, then implements the mapping by binning the variables v1, v2 and assigning each bin combination to a colour.

Usage

ScaleBivariate

scale_fill_bivariate( name1 = NULL, name2 = NULL, colors = c("gold", "red4"), n_breaks = 4, breaks = c("quantile", "equal"), flip = c("none", "vertical", "horizontal", "both"), guide_size = 1.5, na.value = NA, na.translate = TRUE, aesthetics = "fill", ... )

scale_color_bivariate( name1 = NULL, name2 = NULL, colors = c("gold", "red4"), n_breaks = 4, breaks = c("quantile", "equal"), flip = c("none", "vertical", "horizontal", "both"), guide_size = 1.5, na.value = NA, na.translate = TRUE, aesthetics = "colour", ... )

scale_colour_bivariate( name1 = NULL, name2 = NULL, colors = c("gold", "red4"), n_breaks = 4, breaks = c("quantile", "equal"), flip = c("none", "vertical", "horizontal", "both"), guide_size = 1.5, na.value = NA, na.translate = TRUE, aesthetics = "colour", ... )

Value

A ScaleBivariate ggproto object.

Format

An object of class ScaleBivariate (inherits from ScaleDiscrete, Scale, ggproto, gg) of length 5.

Arguments

name1, name2

Optional names for v1 and v2. Used as axis titles in the legend. If NULL, the default, the names are taken from the mapping.

colors

A character vector of length two specifying the colors for the bivariate palette.

n_breaks

An integer guiding the number of bins for each variable.

breaks

Method used to bin the variables: "quantile" (the default) or "equal".

flip

Method used to flip the legend: "none" (the default), "vertical", "horizontal", or "both".

guide_size

A numeric value controlling the size of the legend graphic, in centimeters.

na.value

If na.translate = TRUE, what aesthetic value should the missing values be displayed as? Does not apply to position scales where NA is always placed at the far right.

na.translate

Unlike continuous scales, discrete scales can easily show missing values, and do so by default. If you want to remove missing values from a discrete scale, specify na.translate = FALSE.

aesthetics

The names of the aesthetics that this scale works with.

...

Other arguments passed to ggplot2::discrete_scale().

See Also

ggplot2::Scale for the base ggproto class that all scale objects inherit from.

Examples

Run this code
# Create a bivariate fill scale
sc <- scale_fill_bivariate()
class(sc)
sc$palette(9)

# Basic bivariate map
p <- ggplot(nc) + geom_sf(aes(fill = duo(value, sd)))

# Customize axis labels
p + scale_fill_bivariate(name1 = 'var1', name2 = 'var2')

Run the code above in your browser using DataLab