Function to create basic histogram with categorical data
elsar_plot_distribution.RdFunction to create basic histogram with categorical data
Uso
elsar_plot_distribution(
type = "ggplot",
categorical = TRUE,
raster_df = NULL,
col_interest = NULL,
bin_number = 10,
custom_palette = NULL,
show_legend = FALSE,
color_map = "viridis"
)Argumentos
- type
A character denoting whether "ggplot" or "tmap" is being used.
- categorical
logical. Whether data is categorical (TRUE) or continuous (FALSE).
- raster_df
A
dfobject of the data to include in the histogram.- col_interest
A character of the column of interest. Uses "interval" if nothing is provided.
- bin_number
An integer value of how many bins to split the data into (default = 10).
- custom_palette
An optional custom palette for plotting. Default uses the
viridispackage.- show_legend
logical. Whether to include legend in plot or not. Default is FALSE.
- color_map
The name of the
viridispalette to be used. Default is "viridis".
Exemplos
if (FALSE) { # \dontrun{
boundary_proj <- make_boundary(
boundary_in = boundary_dat,
iso3 = "NPL",
iso3_column = "iso3cd",
custom_projection = TRUE
)
pus <- make_planning_units(boundary_proj = boundary_proj,
iso3 = "NPL",
pu_size = NULL,
pu_threshold = 8.5e5,
limit_to_mainland = FALSE)
wad_dat <- get_wad_data()
wadOut <- make_normalised_raster(raster_in = wad_dat,
pus = pus,
iso3 = "NPL")
plot_cat <- elsar_plot_static_raster_d(
raster_in = wadOut, type = "ggplot_raster",
categorical = FALSE,
background = wad_dat,
number_categories = 10,
data_layer = "wad_final_cog",
raster_df_out = TRUE,
legend_title = "WAD"
)
plot_wad_cat <- plot_cat[[1]]
raster_df_cat <- plot_cat[[2]]
plot_dist_cat <- elsar_plot_distribution(
raster_df = raster_df_cat,
categorical = TRUE
)
(plot_wad_cat_inset <- patchwork::wrap_plots((plot_wad_cat +
elsar_plot_optics()) +
patchwork::inset_element(
(plot_dist_cat +
elsar_plot_optics(include_text = FALSE) +
ggplot2::theme(
axis.title = ggplot2::element_blank(),
axis.text.x = ggplot2::element_blank(),
axis.ticks.x = ggplot2::element_blank()
)
),
left = 0.1, # needs to be changed depending on plot dimensions
bottom = 0.08, # needs to be changed depending on plot dimensions
right = 0.35, # needs to be changed depending on plot dimensions
top = 0.4, # needs to be changed depending on plot dimensions
align_to = "plot"
)))
} # }