Last chance! 50% off unlimited learning
Sale ends in
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)
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
.
A data object, either sf, tibble, or data.frame
Variable breaks should be based on, can be quoted or unquoted
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.
Optional integer scalar; count of the number of classes to create. If you are supplying breaks manually, this can be omitted.
String scalar; one of the classes supported by classInt::classIntervals()
.
"jenks" is the ArcGIS default. "quantile" and "fisher" are better
alternatives. As with classes
, this can be omitted if you are
supplying breaks manually.
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.
Integer; how many significant digits should be applied when calculating breaks and constructing labels?
String scalar; one of either "col"
(default) or
"breaks"
. The default behavior adds a factor containing the bins
to the data object to facilitate mapping. Specifying "breaks"
will return the calculated breaks instead, which can be modified and
passed to the breaks
argument later in a script to make the
final map.
Logical scalar; if TRUE
, warnings created by
classInt::classIntervals()
if NA
values are identified while
findings classes.
# 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)
Run the code above in your browser using DataLab