Description Usage Arguments Details References Examples
Maps two continuous variables into a single display color, using either the
color
and color2
aesthetics (scale_color_colorplane
) or
the fill
and fill2
aesthetics (scale_fill_colorplane
).
Variables mapped to color
or fill
are be mapped to the
horizontal component of the colorplane scale and color
/fill2
are mapped to the vertical component.
1 2 3 4 5 6 7 8 9 10 11 12 13 | scale_color_colorplane(name = waiver(), axis_title = waiver(),
axis_title_y = waiver(), breaks = waiver(), breaks_y = waiver(),
labels = waiver(), labels_y = waiver(), limits = NULL,
limits_y = NULL, color_projection = "YUV", rescaler = rescale,
oob = censor, trans = "identity", na.color = "black",
na.value = NA_real_, guide = "colorplane", ...)
scale_fill_colorplane(name = waiver(), axis_title = waiver(),
axis_title_y = waiver(), breaks = waiver(), breaks_y = waiver(),
labels = waiver(), labels_y = waiver(), limits = NULL,
limits_y = NULL, color_projection = "YUV", rescaler = rescale,
oob = censor, trans = "identity", na.color = "black",
na.value = NA_real_, guide = "colorplane", ...)
|
name |
Character string or expression to be used as guide title. Defaults to "Color Key" or "Fill Color Key" to match the scale function used. |
axis_title, axis_title_y |
Character strings or expressions indicating
the horizontal and vertical axis titles in the guide, respectively. If
|
breaks |
One of:
|
breaks_y |
As |
labels |
One of:
|
labels_y |
As |
limits |
A numeric vector of length two providing limits of the scale.
Use |
limits_y |
As |
color_projection |
Projection mapping to use. Either the name of an
included projection or a function that performs the projection. See
|
rescaler |
Used by diverging and n colour gradients
(i.e. |
oob |
Function that handles limits outside of the scale limits (out of bounds). The default replaces out of bounds values with NA. |
trans |
Either the name of a transformation object, or the object itself. Built-in transformations include "asn", "atanh", "boxcox", "exp", "identity", "log", "log10", "log1p", "log2", "logit", "probability", "probit", "reciprocal", "reverse" and "sqrt". A transformation object bundles together a transform, it's inverse,
and methods for generating breaks and labels. Transformation objects
are defined in the scales package, and are called |
na.color |
Character string containing a valid R color to use when plotting missing data or data outside the limits. |
na.value |
Missing values will be replaced with this value. |
guide |
Name of guide object, or object itself. Defaults to
|
... |
Additional arguments to pass on to |
Variable values are projected into color space to create a bivariate gradient. The default projection maps values to the U and V components of YUV color space. In the YUV color space, the full spectrum of chrominance (color difference) is encoded into the U and V components and luminosity (brightness) is encoded in the Y component. For a fixed value of Y, the remaining U-V color space is a plane of all possible colors at that brightness. Therefore, mapping data to this projection utilizes the full color spectrum to provide visual discrimination between differing values.
The YUV projection colorplane scale is visually divided into four quadrants: green when both values are small, fuchsia when both are large, orange when the horizontal variable is small and the vertical is large, and blue when the horizontal variable is large and the vertical is small. Values closer to the extremes are saturated and the center of the scale, representing the mid-point of the ranges for both variables, is grey.
Alternative color projections can be used, but may not be as interpretable.
See color_projections
for information on specifying or creating
other color projections.
Based on continuous_scale
, modified 2016.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | library(ggplot2)
if(requireNamespace("mapproj")) {
crimes <- data.frame(state = tolower(rownames(USArrests)), USArrests)
states_map <- map_data("state")
ggplot(crimes,
aes(map_id = state, fill = Murder, fill2 = UrbanPop)) +
geom_map(map = states_map) +
scale_fill_colorplane() +
expand_limits(x = states_map$long, y = states_map$lat) +
coord_map()
}
# setting upper limit for qsec causes points for higher values to plot
# as na.color (black)
ggplot(mtcars, aes(x = wt, y = mpg, color = qsec, colour2 = hp)) +
geom_point(size = 4) +
scale_color_colorplane(limits = c(NA, 18.9))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.