if (FALSE) {
# Texas county income data
library(tidycensus)
tx <- get_acs(geography = "county", variables = "B19013_001",
state = "TX", geometry = TRUE)
# Using palette function (recommended)
eq_class <- step_equal_interval(data = tx, column = "estimate", n = 5,
palette = viridisLite::plasma)
# Or with piping
eq_class <- tx |> step_equal_interval("estimate", n = 5)
# Using specific colors
qt_class <- step_quantile(data = tx, column = "estimate", n = 3,
colors = c("red", "yellow", "blue"))
# Jenks natural breaks with default viridis
jk_class <- step_jenks(data = tx, column = "estimate", n = 5)
# Use in a map with formatted legend
maplibre() |>
add_fill_layer(source = tx, fill_color = eq_class$expression) |>
add_legend(
legend_title = "Median Income",
values = get_legend_labels(eq_class, format = "currency"),
colors = get_legend_colors(eq_class),
type = "categorical"
)
# Compare different methods
print(eq_class, format = "currency")
print(qt_class, format = "compact", prefix = "$")
}
Run the code above in your browser using DataLab