Creates mapping classes for a bivariate map. These data will be stored
in a new variable named bi_class, which will be added to the given
data object.
bi_class(.data, x, y, style, dim = 3, keep_factors = FALSE, dig_lab = 3, na_rm = FALSE)A data frame, tibble, or sf object
The x variable, either a numeric (including double and integer
classes) or factor
The y variable, either a numeric (including double and integer
classes) or factor
A string identifying the style used to calculate breaks. Currently
supported styles are "quantile", "equal", "fisher",
and "jenks". If both x and y are factors, this argument can
be omitted.
Note that older versions of biscale used "quantile" as the default
for this argument. Now that bi_class accepts factors, this argument
no longer as a default and older code will error.
The dimensions of the palette. To use the built-in palettes,
this value must be either 2, 3, or 4. A value of
3, for example, would be used to create a three-by-three bivariate
map with a total of 9 classes.
If you are using a custom palette, this value may be larger (though these maps can be very hard to interpret).
If you are using pre-made factors, both factors must have the same number of levels as this value.
A logical scalar; if TRUE, the intermediate factor
variables created as part of the calculation of bi_class will be
retained. If FALSE (default), they will not be returned.
An integer that is passed to base::cut()
A logical scalar that is passed to classInt::classIntervals();
if TRUE, NA values will be removed prior to calculating breaks.
If FALSE (default), they will be included.
A copy of .data with a new variable bi_class that contains
combinations of values that correspond to an observations values for x
and y. This is the basis for applying a bivariate color palette.
# quantile breaks, 2x2
data <- bi_class(stl_race_income, x = pctWhite, y = medInc, style = "quantile", dim = 2)
# summarize quantile breaks, 2x2
table(data$bi_class)
#>
#> 1-1 1-2 2-1 2-2
#> 45 8 8 45
# quantile breaks, 3x3
data <- bi_class(stl_race_income, x = pctWhite, y = medInc, style = "quantile", dim = 3)
# summarize quantile breaks, 3x3
table(data$bi_class)
#>
#> 1-1 1-2 2-1 2-2 2-3 3-2 3-3
#> 25 11 11 17 7 7 28