Creates a categorical scale. Categorical scales map input values defined in the set of
levels
to colours (or values). Input values not in the set of levels
are assigned
unmapped_color
(or unmapped_value
).
Usage
scale_color_category(
col,
palette = scales::brewer_pal("div"),
unmapped_color = "#000000",
levels = NULL,
unmapped_tick = NULL,
tick_format = NULL,
col_label = "{.col}",
legend = TRUE
)
scale_category(
col,
range = 0:1,
unmapped_value = 0,
levels = NULL,
col_label = "{.col}",
legend = TRUE
)
Arguments
- col
<
name
|string
> The name of the column containing data to be scaled. Must be a valid input torlang::ensym()
; either a named column (non-standard evaluation), a string. Supports tidy-eval.- palette
<
color
|function
> The colour palette of the colour scale. Must be a:vector of RGBA hex colours,
a palette generator function, taking a length parameter, or
a palette ramp created from
scales::colour_ramp()
A
scales::colour_ramp()
interpolator is created from the input palette.- unmapped_color
<
color
> The colour representing unmapped levels.- levels
<
factor
|character
|logical
> The category levels. IfNULL
, will be populated from input data. The order of the levels is determined bylevels()
for factors &unique()
otherwise.If there are more levels than colours (or range values), the palette (or range) is interpolated.
- unmapped_tick
<
string
> The tick label of the unmapped category. If notNULL
andlegend == TRUE
, the unmapped category will appear at the bottom of the legend.- tick_format
<
function
> A label function taking a vector of ticks returning formatted ticks.- col_label
<
string
|function
> A template string or a label function for customising the column name in the legend.if
col_label
is a string,{.col}
may be used to represent thecol
nameif
col_label
is a function, the function must take a single argument: thecol
name
- legend
<
boolean
> Indicate whether the legend should be displayed for this scale.- range
<
numeric
> The output range of the numeric scale. Must be length >= 2. Astats::approxfun()
interpolator is created from the input range.- unmapped_value
<
number
> The value representing unmapped levels.
See also
Other scales:
rescale_center()
,
rescale_diverge()
,
scale_identity()
,
scale_linear()
,
scale_log()
,
scale_power()
,
scale_quantile()
,
scale_quantize()
,
scale_symlog()
,
scale_threshold()