Skip to contents

The splnr_plot_selectionFreq() function visualizes the selection frequency of Planning Units across an array of prioritizr solutions. This is useful for understanding which areas are consistently selected as important for conservation.

Usage

splnr_plot_selectionFreq(
  selFreq,
  plotTitle = "",
  paletteName = "Greens",
  legendTitle = "Selection \nFrequency"
)

Arguments

selFreq

An sf object containing the selection frequency data for Planning Units. This object must include a selFreq column (e.g., generated by splnr_get_selFreq()).

plotTitle

A character string for the title of the plot. Defaults to "".

paletteName

A character string or numeric value specifying the name of the RColorBrewer palette to use for the fill. Available palettes can be found at https://ggplot2.tidyverse.org/reference/scale_brewer.html. Defaults to "Greens".

legendTitle

A character string for the title of the legend. Defaults to "Selection \nFrequency".

Value

A ggplot object representing the plot of Planning Unit selection frequency.

Details

When multiple spatial plans are generated (either from solutions to different conservation problems or via a prioritizr portfolio approach), it's valuable to assess the robustness of Planning Unit selection. This function takes an sf object as input, which must contain a selFreq column representing the selection frequency of each Planning Unit. This selFreq column can be generated using the spatialplanr function splnr_get_selFreq().

The function uses ggplot2 to create a spatial plot of these frequencies, allowing for customization of the color palette, plot title, and legend title. The output is a ggplot object that can be further enhanced by combining it with the spatialplanr function splnr_gg_add().

Examples

if (FALSE) { # \dontrun{
# Assuming 'dat_species_bin' is an existing sf object in your package.

# Create a dummy prioritizr problem.
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)

# Create a conservation problem that contains a portfolio of solutions (e.g., 5 solutions).
dat_soln_portfolio <- dat_problem %>%
  prioritizr::add_cuts_portfolio(number_solutions = 5) %>%
  prioritizr::solve.ConservationProblem()

# Calculate selection frequency using splnr_get_selFreq().
selFreq_data <- splnr_get_selFreq(solnMany = dat_soln_portfolio, type = "portfolio")

# Plot the selection frequency.
plot_selection_frequency <- splnr_plot_selectionFreq(selFreq_data)
print(plot_selection_frequency)
} # }