
Plot Circular Barplot for Feature Representation
Source:R/splnr_featureRep.R
splnr_plot_circBplot.Rdsplnr_plot_circBplot() creates a circular bar plot to visualize feature
representation, categorized by groups. It's particularly useful for
displaying how different categories of features meet certain targets in a radial layout.
Usage
splnr_plot_circBplot(
df,
legend_color,
legend_list,
indicateTargets = TRUE,
impTarget = NA,
repTarget = NA,
colTarget = "red"
)Arguments
- df
A data.frame or tibble that must contain the following columns:
- legend_color
A named vector of colors. Names must correspond to the unique values in the
groupcolumn ofdf, and values are the corresponding colors. For example:c("group_name1" = "red", "group_name2" = "blue").- legend_list
A character vector of labels for the legend. This should match the names used in
legend_coloror the levels ofgroup.- indicateTargets
A logical value. If
TRUE, horizontal lines indicatingimpTargetandrepTargetwill be drawn on the plot.- impTarget
A numeric value representing the target percentage for 'important' features. Required if
indicateTargetsisTRUE.- repTarget
A numeric value representing the target percentage for 'representative' features. Required if
indicateTargetsisTRUE.- colTarget
A character string specifying the color for the target indicator lines.
Value
A ggplot2::ggplot object of the circular bar plot.
Examples
# DISCLAIMER: THIS SOLUTION IS NOT ACTUALLY RUN WITH THESE TARGETS YET
if (FALSE) { # \dontrun{
dat_problem <- prioritizr::problem(dat_species_bin %>% dplyr::mutate(Cost = runif(n = dim(.)[[1]])),
features = c("Spp1", "Spp2", "Spp3", "Spp4", "Spp5"),
cost_column = "Cost"
) %>%
prioritizr::add_min_set_objective() %>%
prioritizr::add_relative_targets(0.3) %>%
prioritizr::add_binary_decisions() %>%
prioritizr::add_default_solver(verbose = FALSE)
dat_soln <- dat_problem %>%
prioritizr::solve.ConservationProblem()
s1 <- dat_soln %>%
tibble::as_tibble()
p1 <- dat_problem
# Assuming eval_feature_representation_summary is from prioritizr
df_rep_imp <- prioritizr::eval_feature_representation_summary(
p1,
s1[, "solution_1"]
) %>%
dplyr::select(feature, relative_held) %>%
dplyr::mutate(relative_held = relative_held * 100)
imp_layers <- c("Spp1", "Spp3")
target <- data.frame(feature = c("Spp1", "Spp2", "Spp3", "Spp4", "Spp5")) %>%
dplyr::mutate(class = dplyr::if_else(.data$feature %in% imp_layers,
"important", "representative"
)) %>%
dplyr::mutate(target = dplyr::if_else(class == "important",
50 / 100, 30 / 100
))
df <- merge(df_rep_imp, target) %>%
dplyr::select(-target) %>%
stats::na.omit() %>% # Use stats::na.omit
dplyr::rename(value = relative_held) %>%
dplyr::rename(group = class)
colors <- c(
"important" = "darkgreen",
"representative" = "darkred"
)
legends <- c("Important", "Representative")
(splnr_plot_circBplot(df,
legend_list = legends,
legend_color = colors,
impTarget = 50, repTarget = 30
))
} # }