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 = "quantile", dim = 3, keep_factors = FALSE)

Arguments

.data

A data frame, tibble, or sf object

x

The x variable

y

The y variable

style

A string identifying the style used to calculate breaks. Currently supported styles are "quantile" (default), "equal", "fisher", and "jenks".

dim

The dimensions of the palette, either 2 for a two-by-two palette or 3 for a three-by-three palette.

keep_factors

A logical scalar; if TRUE, the intermediate factor variables created as part of the calculation of bs_class will be retained. If FALSE (default), they will not be returned.

Value

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.

Examples

# quantile breaks, 2x2 data <- bi_class(stl_race_income, x = pctWhite, y = medInc, style = "quantile", dim = 2)
#> Warning: The 'sf' package is not loaded, and the class 'sf' attribute of the given data set has been lost. Load 'sf' to retain the class when using 'bi_class'.
# 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)
#> Warning: The 'sf' package is not loaded, and the class 'sf' attribute of the given data set has been lost. Load 'sf' to retain the class when using 'bi_class'.
# 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
# equal breaks data <- bi_class(stl_race_income, x = pctWhite, y = medInc, style = "equal", dim = 3)
#> Warning: The 'sf' package is not loaded, and the class 'sf' attribute of the given data set has been lost. Load 'sf' to retain the class when using 'bi_class'.
# summarize equal breaks, 3x3 table(data$bi_class)
#> #> 1-1 1-2 2-1 2-2 2-3 3-1 3-2 3-3 #> 42 5 8 13 6 1 13 18
# fisher breaks data <- bi_class(stl_race_income, x = pctWhite, y = medInc, style = "fisher", dim = 3)
#> Warning: The 'sf' package is not loaded, and the class 'sf' attribute of the given data set has been lost. Load 'sf' to retain the class when using 'bi_class'.
# summarize fisher breaks, 3x3 table(data$bi_class)
#> #> 1-1 1-2 2-1 2-2 2-3 3-1 3-2 3-3 #> 38 5 12 13 6 1 9 22
# jenks breaks data <- bi_class(stl_race_income, x = pctWhite, y = medInc, style = "jenks", dim = 3)
#> Warning: The 'sf' package is not loaded, and the class 'sf' attribute of the given data set has been lost. Load 'sf' to retain the class when using 'bi_class'.
# summarize jenks breaks, 3x3 table(data$bi_class)
#> #> 1-1 1-2 2-1 2-2 2-3 3-1 3-2 3-3 #> 38 5 12 13 6 1 9 22