View source: R/dep_map_breaks.R
dep_map_breaks | R Documentation |
Create "bins" for choropleth maps creating using either
ggplot2
or leaflet
. The function can create the bins
automatically or will accept pre-specified breaks.
dep_map_breaks(.data, var, new_var, classes, style, breaks,
sig_digits = 2, return = "col", show_warnings = TRUE)
.data |
A data object, either sf, tibble, or data.frame |
var |
Variable breaks should be based on, can be quoted or unquoted |
new_var |
Optional name of new variable to store breaks in, can be quoted or unquoted. This is required if you are returning a column, but can be omitted if you are returning breaks instead of a column. |
classes |
Optional integer scalar; count of the number of classes to create. If you are supplying breaks manually, this can be omitted. |
style |
String scalar; one of the classes supported by |
breaks |
Optional numeric vector if you want to pre-specify the cut points for your breaks. Provide the lower and upper bounds of your distribution. Any values supplied in between the bounds will be the upper bound of individual bins. |
sig_digits |
Integer; how many significant digits should be applied when calculating breaks and constructing labels? |
return |
String scalar; one of either |
show_warnings |
Logical scalar; if |
Either a data object (if return
is "col"
) or a vector
of breaks (if return
is "breaks"
). If a data object is
returned, the new column will be placed directly after the input variable
specified in var
.
# prep data
## load sample data
ndi_m <- dep_sample_data(index = "ndi_m")
## calculate NDI with sample data
ndi_m <- dep_calc_index(ndi_m, geography = "county", index = "ndi_m", year = 2022,
return_percentiles = TRUE)
# calculate breaks using a built-in algorithm
dep_map_breaks(ndi_m, var = "NDI_M", new_var = "map_breaks", classes = 5,
style = "fisher")
# use manually specified breaks
## set breaks
breaks <- c(0, 25, 50, 75, max(ndi_m$NDI_M))
## calculate breaks
dep_map_breaks(ndi_m, var = "NDI_M", new_var = "map_breaks", breaks = breaks)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.