From a0e415cccef5845abf93d1f2020a8265f156300a Mon Sep 17 00:00:00 2001 From: Jason Everett Date: Mon, 17 Nov 2025 15:31:15 +1100 Subject: [PATCH 1/5] Fix errors and update documentation --- NAMESPACE | 3 - R/data.R | 30 ++-- R/splnr_get_distCoast.R | 14 +- R/splnr_gg_add.R | 137 ++++++++++++------- R/splnr_plotting.R | 52 +++---- R/splnr_plotting_climate.R | 10 +- R/splnr_targets.R | 14 +- R/utils-climate.R | 34 ++--- R/utils.R | 26 ++-- man/MPAsCoralSea.Rd | 6 +- man/dat_PUs.Rd | 2 +- man/dat_bndry.Rd | 4 +- man/dat_category.Rd | 2 +- man/dat_category2.Rd | 2 +- man/dat_clim.Rd | 2 +- man/dat_mpas.Rd | 4 +- man/dat_region.Rd | 2 +- man/dat_species_bin.Rd | 2 +- man/dat_species_bin2.Rd | 2 +- man/dat_species_prob.Rd | 2 +- man/splnr_climate_featureApproach.Rd | 4 +- man/splnr_climate_percentileApproach.Rd | 4 +- man/splnr_climate_priorityAreaApproach.Rd | 6 +- man/splnr_get_distCoast.Rd | 4 +- man/splnr_get_selFreq.Rd | 6 +- man/splnr_gg_add.Rd | 70 +++++++--- man/splnr_plot.Rd | 10 +- man/splnr_plot_climKernelDensity.Rd | 14 +- man/splnr_plot_comparison.Rd | 4 +- man/splnr_plot_costOverlay.Rd | 12 +- man/splnr_plot_importanceScore.Rd | 4 +- man/splnr_plot_selectionFreq.Rd | 10 +- man/splnr_plot_solution.Rd | 2 +- man/splnr_replace_NAs.Rd | 4 +- man/splnr_targets_byInverseArea.Rd | 10 +- tests/testthat/test-splnr_plotting_climate.R | 2 +- vignettes/ClimateSmart.Rmd | 15 +- vignettes/GlobalFishingWatch.Rmd | 11 +- vignettes/MultipleUse.Rmd | 8 +- vignettes/spatialplanr.Rmd | 18 +-- 40 files changed, 319 insertions(+), 249 deletions(-) diff --git a/NAMESPACE b/NAMESPACE index 71160bc7..21b3247f 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -68,11 +68,9 @@ importFrom(dplyr,summarise) importFrom(dplyr,summarize) importFrom(dplyr,tibble) importFrom(dplyr,ungroup) -importFrom(forcats,fct_relevel) importFrom(ggnewscale,new_scale_colour) importFrom(ggnewscale,new_scale_fill) importFrom(ggplot2,aes) -importFrom(ggplot2,after_stat) importFrom(ggplot2,annotate) importFrom(ggplot2,coord_polar) importFrom(ggplot2,coord_sf) @@ -80,7 +78,6 @@ importFrom(ggplot2,element_blank) importFrom(ggplot2,element_line) importFrom(ggplot2,element_rect) importFrom(ggplot2,element_text) -importFrom(ggplot2,expansion) importFrom(ggplot2,geom_abline) importFrom(ggplot2,geom_bar) importFrom(ggplot2,geom_segment) diff --git a/R/data.R b/R/data.R index 83b1a7d3..a5c7650b 100644 --- a/R/data.R +++ b/R/data.R @@ -1,6 +1,6 @@ #' Planning Units #' -#' An sf dataframe of planning units for spatial prioritisation +#' An sf dataframe of Planning Units for spatial prioritization #' #' @format `dat_PUs` #' A data frame with XXXX rows and XXX columns: @@ -14,9 +14,9 @@ # ------------------------------------------------------------------------- -#' Boundary of planning units +#' Boundary of Planning Units #' -#' An sf dataframe of planning units for spatial prioritisation +#' An sf dataframe of Planning Units for spatial prioritization #' #' @format `dat_bndry` #' A data frame with XXXX rows and XXX columns: @@ -32,7 +32,7 @@ #' Regionalisation #' -#' An sf dataframe of planning units for spatial prioritisation +#' An sf dataframe of Planning Units for spatial prioritization #' #' @format `dat_region` #' A data frame with XXXX rows and XXX columns: @@ -47,7 +47,7 @@ #' Binary Species Data #' -#' An sf dataframe of planning units for spatial prioritisation +#' An sf dataframe of Planning Units for spatial prioritization #' #' @format `dat_species_bin` #' A data frame with XXXX rows and XXX columns: @@ -63,7 +63,7 @@ #' Binary Species Data 2 #' -#' An sf dataframe of planning units for spatial prioritisation +#' An sf dataframe of Planning Units for spatial prioritization #' #' @format `dat_species_bin2` #' A data frame with XXXX rows and XXX columns: @@ -79,7 +79,7 @@ #' Probability Species Data #' -#' An sf dataframe of planning units for spatial prioritisation +#' An sf dataframe of Planning Units for spatial prioritization #' #' @format `dat_species_prob` #' A data frame with XXXX rows and XXX columns: @@ -93,9 +93,9 @@ # ------------------------------------------------------------------------- -#' MPA Data +#' Marine Protected Areas (MPAs) Data #' -#' An sf dataframe of planning units for spatial prioritisation +#' An sf dataframe of Planning Units for spatial prioritization #' #' @format `dat_mpas` #' A data frame with XXXX rows and XXX columns: @@ -117,7 +117,7 @@ #' @format `dat_category` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{feature}{all features available for spatial prioritisation} +#' \item{feature}{all features available for spatial prioritization} #' \item{category}{the categories of all features} #' ... #' } @@ -135,7 +135,7 @@ #' @format `dat_category2` #' A data frame with XXXX rows and XXX columns: #' \describe{ -#' \item{feature}{all features available for spatial prioritisation} +#' \item{feature}{all features available for spatial prioritization} #' \item{category}{the categories of all features} #' ... #' } @@ -148,7 +148,7 @@ #' Climate metric data #' -#' An sf dataframe of planning units for spatial prioritisation +#' An sf dataframe of Planning Units for spatial prioritization #' #' @format `dat_clim` #' A data frame with 780 rows and 3 columns: @@ -179,14 +179,14 @@ # ------------------------------------------------------------------------- -#' Current MPAs of the Coral Sea +#' Current Marine Protected Areas (MPAs) of the Coral Sea #' -#' sf file containing the current marine protected areas of the coral sea +#' sf file containing the current Marine Protected Areas (MPAs) of the coral sea #' #' @format `MPAsCoralSea` #' A data frame with 397 rows and 17 columns: #' \describe{ -#' \item{wdpa}{binary vector denoting presence or absence of a current marine protected area} +#' \item{wdpa}{binary vector denoting presence or absence of a current MPA} #' ... #' } #' @source https://www.protectedplanet.net/en/thematic-areas/wdpa?tab=WDPA diff --git a/R/splnr_get_distCoast.R b/R/splnr_get_distCoast.R index 37ac46aa..92f6273d 100644 --- a/R/splnr_get_distCoast.R +++ b/R/splnr_get_distCoast.R @@ -2,7 +2,7 @@ #' #' @description #' This function calculates the shortest distance from the centroid of each -#' planning unit in an `sf` object to the nearest coastline. It can use either +#' Planning Unit in an `sf` object to the nearest coastline. It can use either #' a default coastline from the `rnaturalearth` package or a custom-provided #' coastline `sf` object. #' @@ -13,7 +13,7 @@ #' a suitable projected CRS for accurate distance calculations. #' #' @param dat_sf `[sf]` \cr An `sf` object containing polygon or point features -#' representing the planning units. Must have a valid CRS. +#' representing the Planning Units. Must have a valid CRS. #' @param custom_coast `[sf]` \cr An optional `sf` object representing a #' custom coastline. If `NULL` (the default), the coastline is downloaded #' from `rnaturalearth`. @@ -99,12 +99,12 @@ splnr_get_distCoast <- function(dat_sf, custom_coast = NULL, res = "medium") { sf::st_transform(crs = sf::st_crs(dat_sf)) } - # Calculate centroids of the planning units - # Using centroids is a standard approach to represent the location of each planning unit - message("Calculating centroids for planning units.") + # Calculate centroids of the Planning Units + # Using centroids is a standard approach to represent the location of each Planning Unit + message("Calculating centroids for Planning Units.") grid_centroid <- sf::st_centroid(sf::st_geometry(dat_sf)) - # Calculate the distance matrix between each planning unit centroid and the coastline + # Calculate the distance matrix between each Planning Unit centroid and the coastline message("Calculating distances to coastline.") dist_mat <- sf::st_distance(grid_centroid, coast) %>% # Explicitly set the distance units to kilometers @@ -112,7 +112,7 @@ splnr_get_distCoast <- function(dat_sf, custom_coast = NULL, res = "medium") { # Drop the units class to get a numeric matrix for easier computation units::drop_units() - # Find the minimum distance for each planning unit (each row in the matrix) + # Find the minimum distance for each Planning Unit (each row in the matrix) # This identifies the shortest distance from each centroid to any part of the coastline message("Finding minimum distances and adding to dataframe.") dat_sf$coastDistance_km <- do.call(pmin, as.data.frame(dist_mat)) diff --git a/R/splnr_gg_add.R b/R/splnr_gg_add.R index da747800..c8fd4ad8 100644 --- a/R/splnr_gg_add.R +++ b/R/splnr_gg_add.R @@ -1,16 +1,18 @@ -#' @title Add-ons for Plotting `spatialplanr` Maps +#' @title Add-ons for Plotting `spatialplanr` Solution Maps #' #' @description -#' This function allows users to customize existing `ggplot2` maps, particularly -#' those produced by other `spatialplanr` spatial plotting functions. It provides -#' options to add various spatial layers and apply consistent theming in a +#' This function allows users to customize existing `ggplot2` solution maps produced +#' by `spatialplanr` spatial plotting functions (e.g., `splnr_plot_solution()`). It +#' provides options to add various spatial layers and apply consistent theming in a #' simple and reproducible manner. #' #' @details -#' The `splnr_gg_add` function enhances `ggplot2` objects by layering additional -#' spatial data such as planning unit outlines, study area boundaries, general -#' overlays, geographical contours, and 'locked-in' areas (e.g., existing protected -#' areas in a conservation prioritization). It offers fine-grained control over +#' The `splnr_gg_add()` function enhances `ggplot2` objects by layering additional +#' spatial data such as Planning Unit outlines, study area boundaries, general +#' overlays, geographical contours, locked-in areas (e.g., existing Marine Protected +#' Areas (MPAs) that must be included in a conservation prioritization), and +#' locked-out areas (e.g., areas that must be excluded from selection such as +#' shipping lanes or oil and gas leases). It offers fine-grained control over #' colors, opacities, and legend appearance for each added layer. #' #' When using `contours`, the input `sf` object is expected to have a column @@ -23,10 +25,10 @@ #' or `NA` (logical `FALSE`) to apply no default theme, allowing the user to manage #' all theme elements manually. #' -#' @param PUs An `sf` object representing planning units. If provided, their +#' @param PUs An `sf` object representing Planning Units. If provided, their #' outlines will be drawn. Defaults to `NULL`. #' @param colorPUs A character string specifying the color for the outlines of the -#' planning units. Defaults to `"grey80"`. +#' Planning Units. Defaults to `"grey80"`. #' @param Bndry An `sf` object representing the main planning region boundaries. #' If provided, its outline will be drawn. Defaults to `NULL`. #' @param colorBndry A character string specifying the color for the outline of the @@ -41,15 +43,15 @@ #' @param colorOverlay3 A character string specifying the color for `overlay3`. #' Defaults to `"grey40"`. #' @param cropOverlay An `sf` object. Its bounding box will be used to set the -#' `xlim` and `ylim` of the `ggplot2::coord_sf` layer, effectively cropping the view. +#' `xlim` and `ylim` of the `ggplot2::coord_sf()` layer, effectively cropping the view. #' Defaults to `NULL`. #' @param contours An `sf` object containing contour lines (e.g., bathymetry or #' seamount outlines). It is expected to have a `Category` column for differentiating #' lines. Up to 6 categories are supported. Defaults to `NULL`. #' @param colorConts A character string specifying the color for the contour lines. #' Defaults to `"black"`. -#' @param lockIn An `sf` object representing 'locked-in' areas (e.g., existing -#' Marine Protected Areas) that are fixed in a conservation prioritization. +#' @param lockIn An `sf` object representing locked-in areas (e.g., existing +#' Marine Protected Areas (MPAs)) that are fixed in a conservation prioritization. #' Defaults to `NULL`. #' @param typeLockIn A character string specifying how `lockIn` areas should be #' plotted. Can be `"Full"` (fills the areas with `colorLockIn`) or `"Contours"` @@ -58,13 +60,30 @@ #' data frame that contains binary (0/1 or TRUE/FALSE) information indicating #' locked-in status. Required if `lockIn` is not `NULL`. #' @param alphaLockIn A numeric value (0 to 1) for the opacity of the `lockIn` -#' areas when `typeLockIn` is `"Full"`. Defaults to `0.5`. +#' areas when `typeLockIn` is `"Full"`. Defaults to `1`. #' @param colorLockIn A character string specifying the color for the `lockIn` areas. #' Defaults to `"black"`. #' @param legendLockIn A character string for the title of the `lockIn` legend. #' Can be an empty string `""` to suppress the title. Defaults to `""`. #' @param labelLockIn A character string for the legend label of the `lockIn` areas #' (e.g., "MPAs"). Defaults to `"MPAs"`. +#' @param lockOut An `sf` object representing locked-out areas (e.g., shipping lanes, +#' oil and gas leases, or other excluded zones) that must not be selected in a +#' conservation prioritization. Defaults to `NULL`. +#' @param typeLockOut A character string specifying how `lockOut` areas should be +#' plotted. Can be `"Full"` (fills the areas with `colorLockOut`) or `"Contours"` +#' (draws only the outlines of the areas). Defaults to `"Full"`. +#' @param nameLockOut A character string specifying the column name in the `lockOut` +#' data frame that contains binary (0/1 or TRUE/FALSE) information indicating +#' locked-out status. Required if `lockOut` is not `NULL`. +#' @param alphaLockOut A numeric value (0 to 1) for the opacity of the `lockOut` +#' areas when `typeLockOut` is `"Full"`. Defaults to `1`. +#' @param colorLockOut A character string specifying the color for the `lockOut` areas. +#' Defaults to `"black"`. +#' @param legendLockOut A character string for the title of the `lockOut` legend. +#' Can be an empty string `""` to suppress the title. Defaults to `""`. +#' @param labelLockOut A character string for the legend label of the `lockOut` areas +#' (e.g., "Shipping Lanes"). Defaults to `""`. #' @param ggtheme The `ggplot2` theme to apply. Can be: #' \itemize{ #' \item `NA` or `FALSE`: No theme is applied, using `ggplot2` defaults. @@ -91,7 +110,7 @@ #' @examples #' \dontrun{ #' # Assuming 'dat_species_bin' and 'dat_PUs' are existing sf objects -#' # in your package, suitable for prioritisation problems and plotting. +#' # in your package, suitable for prioritization problems and plotting. #' #' # Create a dummy prioritizr problem and solve it for demonstration. #' dat_problem <- prioritizr::problem( @@ -107,13 +126,13 @@ #' dat_soln <- dat_problem %>% #' prioritizr::solve.ConservationProblem() #' -#' # Basic plot of the solution with default planning unit outlines and theme. +#' # Basic plot of the solution with default Planning Unit outlines and theme. #' plot_basic <- splnr_plot_solution(dat_soln) + #' splnr_gg_add(PUs = dat_PUs, ggtheme = "Default") #' print(plot_basic) #' #' # Example with boundary, a custom overlay, and locked-in areas shown as contours. -#' # For this example, let's create dummy `bndry_sf` and `locked_in_sf` based on `dat_PUs` +#' # For this example, let's create dummy `bndry_sf` and `locked_in_sf` based on `dat_PUs`. #' # In a real scenario, these would be loaded from your package or data. #' bndry_sf <- sf::st_union(dat_PUs) %>% sf::st_as_sf() #' locked_in_sf <- dat_PUs[1:100, ] %>% dplyr::mutate(is_mpa = 1) @@ -125,7 +144,6 @@ #' colorBndry = "darkblue", #' overlay = bndry_sf, # Using boundary as an example overlay #' colorOverlay = "lightblue", -#' alphaOverlay = 0.3, #' lockIn = locked_in_sf, #' typeLockIn = "Contours", #' nameLockIn = "is_mpa", @@ -164,37 +182,58 @@ splnr_gg_add <- function(PUs = NULL, colorPUs = "grey80", # TODO Remove all uneeded arguments, especially the lockIn - # TODO Update the asserts for new arguments - # # Assertions to validate input parameters are of the correct 'sf' class if not NULL. - # if(!is.null(PUs)){assertthat::assert_that(inherits(PUs, "sf"), msg = "'PUs' must be an 'sf' object or NULL.")} - # if(!is.null(Bndry)){assertthat::assert_that(inherits(Bndry, "sf"), msg = "'Bndry' must be an 'sf' object or NULL.")} - # if(!is.null(overlay)){assertthat::assert_that(inherits(overlay, "sf"), msg = "'overlay' must be an 'sf' object or NULL.")} - # if(!is.null(overlay2)){assertthat::assert_that(inherits(overlay2, "sf"), msg = "'overlay2' must be an 'sf' object or NULL.")} - # if(!is.null(overlay3)){assertthat::assert_that(inherits(overlay3, "sf"), msg = "'overlay3' must be an 'sf' object or NULL.")} - # if(!is.null(contours)){assertthat::assert_that(inherits(contours, "sf"), msg = "'contours' must be an 'sf' object or NULL.")} - # if(!is.null(lockIn)){ - # assertthat::assert_that(inherits(lockIn, "sf"), msg = "'lockIn' must be an 'sf' object or NULL.") - # assertthat::assert_that(is.character(nameLockIn) && all(nameLockIn %in% names(lockIn)), - # msg = "If 'lockIn' is provided, 'nameLockIn' must be a character string specifying an existing column in 'lockIn'.") - # assertthat::assert_that(typeLockIn %in% c("Full", "Contours"), - # msg = "'typeLockIn' must be either 'Full' or 'Contours'.") - # assertthat::assert_that(is.numeric(alphaLockIn) && alphaLockIn >= 0 && alphaLockIn <= 1, - # msg = "'alphaLockIn' must be a numeric value between 0 and 1.") - # } - # if(!is.null(cropOverlay)){assertthat::assert_that(inherits(cropOverlay, "sf"), msg = "'cropOverlay' must be an 'sf' object or NULL.")} - # assertthat::assert_that(is.character(colorPUs), msg = "'colorPUs' must be a character string for a color.") - # assertthat::assert_that(is.character(colorBndry), msg = "'colorBndry' must be a character string for a color.") - # assertthat::assert_that(is.character(colorOverlay), msg = "'colorOverlay' must be a character string for a color.") - # assertthat::assert_that(is.character(colorOverlay2), msg = "'colorOverlay2' must be a character string for a color.") - # assertthat::assert_that(is.character(colorOverlay3), msg = "'colorOverlay3' must be a character string for a color.") - # assertthat::assert_that(is.character(colorConts), msg = "'colorConts' must be a character string for a color.") - # assertthat::assert_that(is.character(colorLockIn), msg = "'colorLockIn' must be a character string for a color.") - # assertthat::assert_that(is.character(legendLockIn), msg = "'legendLockIn' must be a character string.") - # assertthat::assert_that(is.character(labelLockIn), msg = "'labelLockIn' must be a character string.") - # assertthat::assert_that( - # inherits(ggtheme, "character") || inherits(ggtheme, "theme") || inherits(ggtheme, "logical"), - # msg = "'ggtheme' must be 'Default', a ggplot2 theme, or NA/FALSE." - # ) + # Assertions to validate input parameters are of the correct 'sf' class if not NULL. + if(!is.null(PUs)){assertthat::assert_that(inherits(PUs, "sf"), msg = "'PUs' must be an 'sf' object or NULL.")} + if(!is.null(Bndry)){assertthat::assert_that(inherits(Bndry, "sf"), msg = "'Bndry' must be an 'sf' object or NULL.")} + if(!is.null(overlay)){assertthat::assert_that(inherits(overlay, "sf"), msg = "'overlay' must be an 'sf' object or NULL.")} + if(!is.null(overlay2)){assertthat::assert_that(inherits(overlay2, "sf"), msg = "'overlay2' must be an 'sf' object or NULL.")} + if(!is.null(overlay3)){assertthat::assert_that(inherits(overlay3, "sf"), msg = "'overlay3' must be an 'sf' object or NULL.")} + if(!is.null(contours)){assertthat::assert_that(inherits(contours, "sf"), msg = "'contours' must be an 'sf' object or NULL.")} + if(!is.null(cropOverlay)){assertthat::assert_that(inherits(cropOverlay, "sf"), msg = "'cropOverlay' must be an 'sf' object or NULL.")} + + # Validate lockIn parameters + if(!is.null(lockIn)){ + assertthat::assert_that(inherits(lockIn, "sf"), msg = "'lockIn' must be an 'sf' object or NULL.") + assertthat::assert_that(is.character(nameLockIn) && !is.null(nameLockIn) && all(nameLockIn %in% names(lockIn)), + msg = "If 'lockIn' is provided, 'nameLockIn' must be a character string specifying an existing column in 'lockIn'.") + assertthat::assert_that(typeLockIn %in% c("Full", "Contours"), + msg = "'typeLockIn' must be either 'Full' or 'Contours'.") + assertthat::assert_that(is.numeric(alphaLockIn) && alphaLockIn >= 0 && alphaLockIn <= 1, + msg = "'alphaLockIn' must be a numeric value between 0 and 1.") + } + + # Validate lockOut parameters + if(!is.null(lockOut)){ + assertthat::assert_that(inherits(lockOut, "sf"), msg = "'lockOut' must be an 'sf' object or NULL.") + assertthat::assert_that(is.character(nameLockOut) && !is.null(nameLockOut) && all(nameLockOut %in% names(lockOut)), + msg = "If 'lockOut' is provided, 'nameLockOut' must be a character string specifying an existing column in 'lockOut'.") + assertthat::assert_that(typeLockOut %in% c("Full", "Contours"), + msg = "'typeLockOut' must be either 'Full' or 'Contours'.") + assertthat::assert_that(is.numeric(alphaLockOut) && alphaLockOut >= 0 && alphaLockOut <= 1, + msg = "'alphaLockOut' must be a numeric value between 0 and 1.") + } + + # Validate color parameters + assertthat::assert_that(is.character(colorPUs), msg = "'colorPUs' must be a character string for a color.") + assertthat::assert_that(is.character(colorBndry), msg = "'colorBndry' must be a character string for a color.") + assertthat::assert_that(is.character(colorOverlay), msg = "'colorOverlay' must be a character string for a color.") + assertthat::assert_that(is.character(colorOverlay2), msg = "'colorOverlay2' must be a character string for a color.") + assertthat::assert_that(is.character(colorOverlay3), msg = "'colorOverlay3' must be a character string for a color.") + assertthat::assert_that(is.character(colorConts), msg = "'colorConts' must be a character string for a color.") + assertthat::assert_that(is.character(colorLockIn), msg = "'colorLockIn' must be a character string for a color.") + assertthat::assert_that(is.character(colorLockOut), msg = "'colorLockOut' must be a character string for a color.") + + # Validate legend and label parameters + assertthat::assert_that(is.character(legendLockIn), msg = "'legendLockIn' must be a character string.") + assertthat::assert_that(is.character(labelLockIn), msg = "'labelLockIn' must be a character string.") + assertthat::assert_that(is.character(legendLockOut), msg = "'legendLockOut' must be a character string.") + assertthat::assert_that(is.character(labelLockOut), msg = "'labelLockOut' must be a character string.") + + # Validate ggtheme parameter + assertthat::assert_that( + inherits(ggtheme, "character") || inherits(ggtheme, "theme") || inherits(ggtheme, "list") || inherits(ggtheme, "logical"), + msg = "'ggtheme' must be 'Default', a ggplot2 theme, a list of theme elements, or NA/FALSE." + ) # Initialize an empty list to store ggplot2 layers. ggList <- list() diff --git a/R/splnr_plotting.R b/R/splnr_plotting.R index 76f0fe4d..cb013d22 100644 --- a/R/splnr_plotting.R +++ b/R/splnr_plotting.R @@ -4,14 +4,14 @@ #' This function provides a versatile way to plot spatial data (`sf` objects) #' within the `spatialplanr` package. It can visualize various data types, #' including binary presence/absence, logical values, continuous data, or simply -#' the planning unit outlines. +#' the Planning Unit outlines. #' #' @details -#' The `splnr_plot` function automatically detects the type of data specified by +#' The `splnr_plot()` function automatically detects the type of data specified by #' `colNames` (binary, logical, or continuous) and adjusts the plotting #' aesthetics accordingly. If multiple `colNames` are provided, it calculates -#' the sum of features for each planning unit and plots this sum. If `colNames` -#' is `NULL`, it will simply plot the outlines of the planning units. +#' the sum of features for each Planning Unit and plots this sum. If `colNames` +#' is `NULL`, it will simply plot the outlines of the Planning Units. #' #' This function is designed to be a flexible replacement for several plotting #' functions, such as `splnr_plot_cost()`, `splnr_plot_binFeature()`, @@ -24,7 +24,7 @@ #' @param df The input dataframe containing the data to be plotted. This must be #' an `sf` object and include a geometry column. #' @param colNames A character vector of column names from `df` to be used for -#' coloring the plot. If `NULL` (default), only the planning unit outlines are plotted. +#' coloring the plot. If `NULL` (default), only the Planning Unit outlines are plotted. #' If a single column is specified, it checks for binary, logical, or continuous data. #' If multiple columns are specified, it sums the values across these columns to create #' a "FeatureSum" for plotting. @@ -258,9 +258,9 @@ splnr_plot <- function(df, ggplot2::guides(fill = ggplot2::guide_colourbar(order = 1), colour = "none") - } else if (is.null(colNames)){ # If no column to plot by (only planning unit outlines). + } else if (is.null(colNames)){ # If no column to plot by (only Planning Unit outlines). - # Add geom_sf to display planning unit outlines without fill. + # Add geom_sf to display Planning Unit outlines without fill. gg <- gg + ggplot2::geom_sf(data = df, colour = "grey80", fill = NA, size = 0.1) } @@ -284,7 +284,7 @@ splnr_plot <- function(df, #' by combining it with the `spatialplanr` function `splnr_gg_add()`. #' #' For multi-zone problems (`zones = TRUE`), the function sums the selected -#' zones for each planning unit and plots the resulting combined selection. +#' zones for each Planning Unit and plots the resulting combined selection. #' The `colorVals` and `legendLabels` should be provided to match the number of #' selection levels (e.g., "Not selected", "Zone 1", "Zone 2", etc.). #' @@ -448,7 +448,7 @@ splnr_plot_solution <- function(soln, colorVals = c("#c6dbef", "#3182bd"), ) } - # Sum up the zone selections for each planning unit to get a single 'solution' column. + # Sum up the zone selections for each Planning Unit to get a single 'solution' column. soln <- solnNewNames %>% dplyr::rowwise() %>% dplyr::mutate( @@ -504,24 +504,24 @@ splnr_plot_solution <- function(soln, colorVals = c("#c6dbef", "#3182bd"), #' @title Plot Cost Overlay on Solution #' #' @description -#' The `splnr_plot_costOverlay()` function visualizes the cost of each planning -#' unit overlaid on the solution of a `prioritizr` conservation problem. This +#' The `splnr_plot_costOverlay()` function visualizes the cost of each Planning +#' Unit overlaid on the solution of a `prioritizr` conservation problem. This #' allows for a customizable `ggplot2` visualization, highlighting the costs -#' within selected planning units. +#' within selected Planning Units. #' #' @details #' This function requires a `prioritizr` solution as an `sf` object, which #' must contain a `solution_1` column indicating selected (1) or unselected (0) -#' planning units. It also requires a cost column, either present within the +#' Planning Units. It also requires a cost column, either present within the #' `soln` object or provided separately via the `Cost` parameter. #' -#' The function filters the solution to show only the selected planning units +#' The function filters the solution to show only the selected Planning Units #' and then overlays these with a gradient representing the cost. This output #' is a `ggplot` object that can be further customized using `splnr_gg_add()`. #' #' @param soln The `prioritizr` solution object, expected as an `sf` object, #' containing at least a `solution_1` column. -#' @param cost An `sf` object containing the cost data for planning units. +#' @param cost An `sf` object containing the cost data for Planning Units. #' If the `prioritizr` solution `soln` already contains the cost column #' specified by `costName`, this parameter can be `NA` (default). Otherwise, #' provide an `sf` object with the cost data. @@ -622,7 +622,7 @@ splnr_plot_costOverlay <- function(soln, cost = NA, costName = "Cost", stop(paste0("The provided 'Cost' object does not contain the specified cost column '", costName, "'.")) } - # Filter the solution to only include selected planning units. + # Filter the solution to only include selected Planning Units. soln <- soln %>% dplyr::select("solution_1") %>% dplyr::filter(.data$solution_1 == 1) @@ -658,7 +658,7 @@ splnr_plot_costOverlay <- function(soln, cost = NA, costName = "Cost", #' @description #' The `splnr_plot_comparison()` function spatially visualizes the differences #' between two `prioritizr` conservation solutions. This helps in understanding -#' which planning units are common, added, or removed between two scenarios. +#' which Planning Units are common, added, or removed between two scenarios. #' #' @details #' Conservation planning often involves comparing outputs from different @@ -667,7 +667,7 @@ splnr_plot_costOverlay <- function(soln, cost = NA, costName = "Cost", #' `prioritizr` solution and containing a `solution_1` column (binary, #' indicating selected vs. not selected). #' -#' The function categorizes planning units into "Same" (selected in both), +#' The function categorizes Planning Units into "Same" (selected in both), #' "Added (+)" (selected in `soln2` but not `soln1`), and "Removed (-)" #' (selected in `soln1` but not `soln2`). It then plots these categories with #' distinct colors for clear visualization. The output is a `ggplot` object @@ -770,7 +770,7 @@ splnr_plot_comparison <- function(soln1, soln2, legendTitle = "Scenario 2 compar ), Compare = factor(.data$Compare, levels = c("Added (+)", "Same", "Removed (-)")) # Set factor levels for consistent plotting order. ) %>% - # Filter out any planning units that are NA in the 'Compare' column (e.g., neither were selected in either scenario). + # Filter out any Planning Units that are NA in the 'Compare' column (e.g., neither were selected in either scenario). dplyr::filter(!is.na(.data$Compare)) # Initialize the ggplot object. @@ -794,16 +794,16 @@ splnr_plot_comparison <- function(soln1, soln2, legendTitle = "Scenario 2 compar #' #' @description #' The `splnr_plot_selectionFreq()` function visualizes the selection frequency -#' of planning units across an array of `prioritizr` solutions. This is useful +#' of Planning Units across an array of `prioritizr` solutions. This is useful #' for understanding which areas are consistently selected as important for #' conservation. #' #' @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 +#' 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` +#' 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, @@ -811,7 +811,7 @@ splnr_plot_comparison <- function(soln1, soln2, legendTitle = "Scenario 2 compar #' The output is a `ggplot` object that can be further enhanced by combining it #' with the `spatialplanr` function `splnr_gg_add()`. #' -#' @param selFreq An `sf` object containing the selection frequency data for planning units. +#' @param 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()`). #' @param plotTitle A character string for the title of the plot. Defaults to `""`. #' @param paletteName A character string or numeric value specifying the name of the @@ -821,7 +821,7 @@ splnr_plot_comparison <- function(soln1, soln2, legendTitle = "Scenario 2 compar #' @param legendTitle A character string for the title of the legend. #' Defaults to `"Selection \nFrequency"`. #' -#' @return A `ggplot` object representing the plot of planning unit selection frequency. +#' @return A `ggplot` object representing the plot of Planning Unit selection frequency. #' @export #' #' @importFrom assertthat assert_that @@ -928,11 +928,11 @@ splnr_plot_selectionFreq <- function(selFreq, #' #' @description #' The `splnr_plot_importanceScore()` function visualizes the importance scores -#' (irreplaceability) of planning units from a `prioritizr` conservation problem +#' (irreplaceability) of Planning Units from a `prioritizr` conservation problem #' using `ggplot2`. It supports different methods for calculating importance scores. #' #' @details -#' Importance scores quantify the irreplaceability of a planning unit in a +#' Importance scores quantify the irreplaceability of a Planning Unit in a #' conservation solution. This function leverages the `prioritizr` package to #' calculate and plot three different types of importance scores: #' \itemize{ diff --git a/R/splnr_plotting_climate.R b/R/splnr_plotting_climate.R index eed0d9ea..596638a7 100644 --- a/R/splnr_plotting_climate.R +++ b/R/splnr_plotting_climate.R @@ -412,16 +412,17 @@ splnr_plot_climKernelDensity_Fancy <- function(solution_list, #' stakeholder engagement. #' #' Both underlying functions require a `prioritizr` solution containing a -#' `metric` column with climate metric information and a `solution_1` column +#' climate metric column with climate metric information and a prioritizr solution column #' indicating selected planning units. #' #' @param soln For `type = "Normal"`: A `list` of `prioritizr` solution objects #' (e.g., `list(s1, s2)`). Each solution must contain a `metric` column and #' a `solution_1` column. #' For `type = "Basic"`: A single `prioritizr` solution `sf` object. -#' @param names A character vector of names corresponding to each solution in +#' @param solution_names A character vector of names corresponding to each solution in #' `soln` when `type = "Normal"`. Not used for `type = "Basic"`. #' Defaults to `NA`. +#' @param climate_names A character string of the name of the climate #' @param type A character string specifying the plotting style. Must be either #' `"Normal"` or `"Basic"`. Defaults to `"Normal"`. #' @param colorMap A character string indicating the `viridis` color map to use @@ -491,7 +492,7 @@ splnr_plot_climKernelDensity_Fancy <- function(solution_list, #' # Example 2: Normal (Fancy) kernel density plot for a single solution #' plot_normal_kde_single <- splnr_plot_climKernelDensity( #' soln = list(dat_solnClim), -#' names = c("Solution 1"), +#' solution_names = c("Solution 1"), #' type = "Normal" #' ) #' print(plot_normal_kde_single) @@ -503,7 +504,8 @@ splnr_plot_climKernelDensity_Fancy <- function(solution_list, #' #' plot_normal_kde_multi <- splnr_plot_climKernelDensity( #' soln = list(dat_solnClim, dat_solnClim_2), -#' names = c("Solution A", "Solution B"), +#' solution_names = c("Solution A", "Solution B"), +#' climate_names = "metric", #' type = "Normal", #' colorMap = "plasma", #' legendTitle = "Climate Value", diff --git a/R/splnr_targets.R b/R/splnr_targets.R index 76851fae..2d398edb 100644 --- a/R/splnr_targets.R +++ b/R/splnr_targets.R @@ -13,10 +13,10 @@ #' range-restricted features. #' #' The calculation proceeds as follows: -#' 1. The area of a single planning unit is determined. +#' 1. The area of a single Planning Unit is determined. #' 2. The total area of the study region is estimated by multiplying the number -#' of planning units by the individual planning unit area. -#' 3. For each feature (species), its total area across all planning units is +#' of Planning Units by the individual Planning Unit area. +#' 3. For each feature (species), its total area across all Planning Units is #' calculated. #' 4. The target for each feature is then scaled between `target_min` and #' `target_max` such that features with smaller areas receive targets closer @@ -25,11 +25,11 @@ #' #' The input `df` is expected to be an `sf` object where columns (excluding #' geometry) represent different features (e.g., species presence/absence) and -#' rows represent planning units. +#' rows represent Planning Units. #' #' @param df An `sf` dataframe containing the features (e.g., species distribution #' data) for which to calculate inverse area targets. Each column (excluding -#' geometry) should represent a feature, and each row a planning unit. +#' geometry) should represent a feature, and each row a Planning Unit. #' @param target_min A numeric value between 0 and 1 (inclusive) specifying the #' minimum target percentage. This will be the target for the most widespread feature. #' @param target_max A numeric value between 0 and 1 (inclusive) specifying the @@ -85,7 +85,7 @@ splnr_targets_byInverseArea <- function(df, target_min, target_max) { msg = "'df' must contain a 'geometry' column." ) - # Calculate the area of a single planning unit in km². + # Calculate the area of a single Planning Unit in km². PU_area_km2 <- as.numeric(sf::st_area(df[1, ]) / 1e+06) # Calculate the total approximate area of the study region. @@ -354,7 +354,7 @@ splnr_targets_byIUCN <- function(dat, IUCN_target, IUCN_col = "IUCN_Category") { # Use coalesce to update 'target' only where new IUCN_target_value is not NA. dplyr::mutate(target = dplyr::coalesce(.data$IUCN_target_value, .data$target)) %>% # Remove the temporary IUCN_target_value column. - dplyr::select(-.data$IUCN_target_value) + dplyr::select(-"IUCN_target_value") } else if (is.numeric(IUCN_target) && length(IUCN_target) == 1) { # If IUCN_target is a single numeric, apply to specific threatened IUCN categories. diff --git a/R/utils-climate.R b/R/utils-climate.R index 4710608f..e5de6a96 100644 --- a/R/utils-climate.R +++ b/R/utils-climate.R @@ -35,9 +35,9 @@ #' #' @param features An `sf` object representing conservation features. Each column #' (excluding geometry) should typically be a binary representation of a feature's -#' presence (1) or absence (0) in each planning unit. +#' presence (1) or absence (0) in each Planning Unit. #' @param metric An `sf` object containing climate metric information. It must -#' have a column named 'metric' with the climate metric values for each planning unit. +#' have a column named 'metric' with the climate metric values for each Planning Unit. #' @param percentile A numeric value (0-100) representing the cutoff threshold for #' determining climate-smart areas. For example, `percentile = 5` means the #' most climate-smart 5% of areas (based on `direction`) are considered. @@ -144,7 +144,7 @@ splnr_climate_priorityArea_preprocess <- function(features, # Handle cases where filteredDF might be empty (feature not present in any unit or only in NAs) if (nrow(filteredDF) == 0) { - warning(paste0("Feature '", spp[i], "' is not present in any planning unit with valid metric data. Skipping climate-smart area calculation for this feature.")) + warning(paste0("Feature '", spp[i], "' is not present in any Planning Unit with valid metric data. Skipping climate-smart area calculation for this feature.")) # Create an empty sf object with expected columns for binding later temp_df <- df %>% dplyr::mutate(V1 = 0, V2 = 0) %>% # Add V1 and V2 columns with 0 values @@ -459,9 +459,9 @@ splnr_climate_priorityArea_assignTargets <- function(targets, #' @param features An `sf` object representing conservation features (e.g., species #' distribution data). Each column (excluding geometry) should typically be a #' binary representation of a feature's presence (1) or absence (0) in each -#' planning unit. +#' Planning Unit. #' @param metric An `sf` object containing climate metric information. It must -#' have a column named 'metric' with the climate metric values per planning unit. +#' have a column named 'metric' with the climate metric values per Planning Unit. #' @param targets A `data.frame` with two columns: `feature` (character, listing #' the original feature names) and `target` (numeric, the initial conservation #' target for each feature as a proportion, e.g., 0.3). @@ -480,7 +480,7 @@ splnr_climate_priorityArea_assignTargets <- function(targets, #' @return A `list` with two components: #' \itemize{ #' \item `Features`: An `sf` object containing the binary information per -#' planning unit for each feature, now split into `_CS` (climate-smart) +#' Planning Unit for each feature, now split into `_CS` (climate-smart) #' and `_NCS` (non-climate-smart) components. This is ready to be #' passed to `prioritizr` when creating a conservation problem. #' \item `Targets`: A `data.frame` with the adjusted targets for the @@ -621,7 +621,7 @@ splnr_climate_priorityAreaApproach <- function(features, #' #' @param features An `sf` object representing conservation features. #' @param metric An `sf` object containing climate metric information. It must -#' have a column named 'metric' with the climate metric values per planning unit. +#' have a column named 'metric' with the climate metric values per Planning Unit. #' @param percentile A numeric value (0-100) representing the cutoff threshold for #' determining whether an area is a climate priority area or not. This is applied #' globally to the `metric` data. @@ -632,8 +632,8 @@ splnr_climate_priorityAreaApproach <- function(features, #' } #' #' @return An `sf` dataframe identical to the input `features`, but with an -#' additional binary column named `climate_layer` indicating which planning -#' units are considered climate-smart. +#' additional binary column named `climate_layer` indicating which Planning +#' Units are considered climate-smart. #' @keywords internal #' @noRd #' @importFrom assertthat assert_that @@ -888,7 +888,7 @@ splnr_climate_feature_assignTargets <- function(climateSmartDF, #' @param features An `sf` object representing conservation features (e.g., species #' distribution data). #' @param metric An `sf` object containing climate metric information. It must -#' have a column named 'metric' with the climate metric values per planning unit. +#' have a column named 'metric' with the climate metric values per Planning Unit. #' @param targets A `data.frame` with two columns: `feature` (character, listing #' the original feature names) and `target` (numeric, the initial conservation #' target for each feature as a proportion, e.g., 0.3). @@ -906,7 +906,7 @@ splnr_climate_feature_assignTargets <- function(climateSmartDF, #' @return A `list` with two components: #' \itemize{ #' \item `Features`: An `sf` object containing the binary information per -#' planning unit for each original feature, plus the new `climate_layer` +#' Planning Unit for each original feature, plus the new `climate_layer` #' feature. This is ready to be passed to `prioritizr`. #' \item `Targets`: A `data.frame` with the adjusted targets for all features, #' including the `climate_layer`. This is also ready for `prioritizr`. @@ -1052,9 +1052,9 @@ splnr_climate_featureApproach <- function(features, #' #' @param features An `sf` object representing conservation features. Each column #' (excluding geometry) should typically be a binary representation of a feature's -#' presence (1) or absence (0) in each planning unit. +#' presence (1) or absence (0) in each Planning Unit. #' @param metric An `sf` object containing climate metric information. It must -#' have a column named 'metric' with the climate metric values per planning unit. +#' have a column named 'metric' with the climate metric values per Planning Unit. #' @param percentile A numeric value (0-100) representing the cutoff threshold for #' determining whether an area is a climate priority area or not. This is applied #' *per feature* to its distribution. @@ -1066,7 +1066,7 @@ splnr_climate_featureApproach <- function(features, #' #' @return An `sf` dataframe where each column represents an original feature, #' but its values are now filtered (`_filtered` suffix implicitly removed in `rename_all`) -#' to 1 only in planning units that are part of its climate-smart percentile. +#' to 1 only in Planning Units that are part of its climate-smart percentile. #' All other values are 0. The dataframe retains the original geometry. #' @keywords internal #' @noRd @@ -1164,7 +1164,7 @@ splnr_climate_percentile_preprocess <- function(features, # Handle cases where filteredDF might be empty (feature not present in any unit or only in NAs) if (nrow(filteredDF) == 0) { - warning(paste0("Feature '", spp[i], "' is not present in any planning unit with valid metric data. Skipping percentile calculation for this feature.")) + warning(paste0("Feature '", spp[i], "' is not present in any Planning Unit with valid metric data. Skipping percentile calculation for this feature.")) # Create an empty df with expected column for binding later temp_df <- df %>% sf::st_drop_geometry() %>% # Drop geometry for consistency with other iterations @@ -1409,7 +1409,7 @@ splnr_climate_percentile_assignTargets <- function(features, #' @param features An `sf` object representing conservation features (e.g., species #' distribution data). #' @param metric An `sf` object containing climate metric information. It must -#' have a column named 'metric' with the climate metric values per planning unit. +#' have a column named 'metric' with the climate metric values per Planning Unit. #' @param targets A `data.frame` with two columns: `feature` (character, listing #' the original feature names) and `target` (numeric, the initial conservation #' target for each feature as a proportion, e.g., 0.3). @@ -1425,7 +1425,7 @@ splnr_climate_percentile_assignTargets <- function(features, #' @return A `list` with two components: #' \itemize{ #' \item `Features`: An `sf` object containing the binary information per -#' planning unit for each feature, now filtered to include only its +#' Planning Unit for each feature, now filtered to include only its #' climate-smart occurrences. This is ready to be passed to `prioritizr`. #' \item `Targets`: A `data.frame` with the adjusted targets for the #' filtered features. This is also ready for `prioritizr`. diff --git a/R/utils.R b/R/utils.R index 8d1cbebb..0cc1fd77 100644 --- a/R/utils.R +++ b/R/utils.R @@ -97,8 +97,8 @@ splnr_create_polygon <- function(x, cCRS = "EPSG:4326") { #' #' @details #' This function is useful for imputing missing data in spatial contexts. -#' It identifies all planning units with `NA` values in the `vari` column. -#' For each of these, it finds the geographically closest planning unit that +#' It identifies all Planning Units with `NA` values in the `vari` column. +#' For each of these, it finds the geographically closest Planning Unit that #' *does not* have an `NA` value in `vari`, and then copies that non-missing #' value. This approach leverages the spatial autocorrelation often present #' in environmental and species data. @@ -677,7 +677,7 @@ splnr_get_kappaCorrData <- function(sol, name_sol) { # Transform the long-format results into a wide-format correlation matrix. matrix_final <- s_matrix_all %>% tibble::as_tibble(.name_repair = "unique") %>% - dplyr::select(-.data$kappa_pvalue) %>% # Remove p-value column as it's not needed for the correlation matrix plot. + dplyr::select(-"kappa_pvalue") %>% # Remove p-value column as it's not needed for the correlation matrix plot. tidyr::pivot_wider(names_from = "plan2", values_from = "kappa_corrvalue") %>% # Pivot to make 'plan2' names as new columns. as.matrix() # Convert to matrix format. @@ -700,7 +700,7 @@ splnr_get_kappaCorrData <- function(sol, name_sol) { #' @title Prepare Data to Plot Selection Frequency of Planning Units #' #' @description -#' `splnr_get_selFreq()` calculates how many times each planning unit is +#' `splnr_get_selFreq()` calculates how many times each Planning Unit is #' selected across an array of `prioritizr` solutions. This "selection #' frequency" can be derived from either a list of individual solutions or #' a `prioritizr` portfolio object. @@ -711,7 +711,7 @@ splnr_get_kappaCorrData <- function(sol, name_sol) { #' planning scenarios or alternative optimal solutions. #' #' The function supports two types of input: -#' \itemize{ +#' \itemize{ #' \item `"portfolio"`: If `solnMany` is a single `sf` object representing a #' portfolio of solutions (e.g., generated by `prioritizr::add_cuts_portfolio()`). #' In this case, the function assumes columns starting with "solution_" @@ -721,7 +721,7 @@ splnr_get_kappaCorrData <- function(sol, name_sol) { #' "solution_1" column). #' } #' For both types, the function sums the binary `solution` values (0 or 1) -#' across all solutions for each planning unit. The result is converted to a +#' across all solutions for each Planning Unit. The result is converted to a #' factor to represent discrete frequency levels. #' #' The output `sf` object can then be passed to `splnr_plot_selectionFreq()` @@ -737,7 +737,7 @@ splnr_get_kappaCorrData <- function(sol, name_sol) { #' #' @return An `sf` object (`selFreq`) containing a column named `selFreq`. #' This column is a factor representing the selection frequency (sum of -#' selected occurrences across all solutions) for each planning unit. +#' selected occurrences across all solutions) for each Planning Unit. #' @export #' #' @importFrom assertthat assert_that @@ -817,7 +817,7 @@ splnr_get_selFreq <- function(solnMany, type = "portfolio") { # Calculate selection frequency for a portfolio (sf object with multiple solution columns). selFreq <- solnMany %>% # Convert to tibble for dplyr operations on columns, ensuring unique names. - dplyr::mutate(selFreq = as.factor(rowSums(dplyr::select(tibble::as_tibble(.), + dplyr::mutate(selFreq = as.factor(rowSums(dplyr::select(tibble::as_tibble(solnMany), dplyr::starts_with("solution_")), na.rm = TRUE))) %>% # Convert back to sf, explicitly retaining the original geometry. sf::st_as_sf(geometry = sf::st_geometry(solnMany)) %>% @@ -863,13 +863,11 @@ splnr_get_selFreq <- function(solnMany, type = "portfolio") { colnames(soln) <- name_sol # Calculate selection frequency by summing binary solution columns. + # Sum across all columns starting with "soln" (which are our individual solutions). selFreq <- soln %>% - # Sum across all columns starting with "soln" (which are our individual solutions). - dplyr::mutate(selFreq = as.factor(rowSums(dplyr::select(., dplyr::starts_with("soln")), na.rm = TRUE))) %>% - # Convert back to sf, using the geometry from the first solution in the list. - sf::st_as_sf(geometry = sf::st_geometry(solnMany[[1]])) %>% - # Select only the calculated selection frequency column. - dplyr::select("selFreq") + dplyr::mutate(selFreq = as.factor(rowSums(dplyr::select(soln, dplyr::starts_with("soln")), na.rm = TRUE))) %>% + sf::st_as_sf(geometry = sf::st_geometry(solnMany[[1]])) %>% # Convert back to sf + dplyr::select("selFreq") # Select only the calculated selection frequency column. return(selFreq) } else { diff --git a/man/MPAsCoralSea.Rd b/man/MPAsCoralSea.Rd index f555ced9..5e9e922d 100644 --- a/man/MPAsCoralSea.Rd +++ b/man/MPAsCoralSea.Rd @@ -3,12 +3,12 @@ \docType{data} \name{MPAsCoralSea} \alias{MPAsCoralSea} -\title{Current MPAs of the Coral Sea} +\title{Current Marine Protected Areas (MPAs) of the Coral Sea} \format{ \code{MPAsCoralSea} A data frame with 397 rows and 17 columns: \describe{ -\item{wdpa}{binary vector denoting presence or absence of a current marine protected area} +\item{wdpa}{binary vector denoting presence or absence of a current MPA} ... } } @@ -19,6 +19,6 @@ https://www.protectedplanet.net/en/thematic-areas/wdpa?tab=WDPA MPAsCoralSea } \description{ -sf file containing the current marine protected areas of the coral sea +sf file containing the current Marine Protected Areas (MPAs) of the coral sea } \keyword{datasets} diff --git a/man/dat_PUs.Rd b/man/dat_PUs.Rd index 49da8aa5..e2d1c510 100644 --- a/man/dat_PUs.Rd +++ b/man/dat_PUs.Rd @@ -19,6 +19,6 @@ A data frame with XXXX rows and XXX columns: dat_PUs } \description{ -An sf dataframe of planning units for spatial prioritisation +An sf dataframe of Planning Units for spatial prioritization } \keyword{datasets} diff --git a/man/dat_bndry.Rd b/man/dat_bndry.Rd index 8e82b80b..c6c271a9 100644 --- a/man/dat_bndry.Rd +++ b/man/dat_bndry.Rd @@ -3,7 +3,7 @@ \docType{data} \name{dat_bndry} \alias{dat_bndry} -\title{Boundary of planning units} +\title{Boundary of Planning Units} \format{ \code{dat_bndry} A data frame with XXXX rows and XXX columns: @@ -19,6 +19,6 @@ A data frame with XXXX rows and XXX columns: dat_bndry } \description{ -An sf dataframe of planning units for spatial prioritisation +An sf dataframe of Planning Units for spatial prioritization } \keyword{datasets} diff --git a/man/dat_category.Rd b/man/dat_category.Rd index fad59363..24d2b460 100644 --- a/man/dat_category.Rd +++ b/man/dat_category.Rd @@ -8,7 +8,7 @@ \code{dat_category} A data frame with XXXX rows and XXX columns: \describe{ -\item{feature}{all features available for spatial prioritisation} +\item{feature}{all features available for spatial prioritization} \item{category}{the categories of all features} ... } diff --git a/man/dat_category2.Rd b/man/dat_category2.Rd index 628e7ace..e3421069 100644 --- a/man/dat_category2.Rd +++ b/man/dat_category2.Rd @@ -8,7 +8,7 @@ \code{dat_category2} A data frame with XXXX rows and XXX columns: \describe{ -\item{feature}{all features available for spatial prioritisation} +\item{feature}{all features available for spatial prioritization} \item{category}{the categories of all features} ... } diff --git a/man/dat_clim.Rd b/man/dat_clim.Rd index 0a686c54..ad2d0d49 100644 --- a/man/dat_clim.Rd +++ b/man/dat_clim.Rd @@ -20,6 +20,6 @@ A data frame with 780 rows and 3 columns: dat_clim } \description{ -An sf dataframe of planning units for spatial prioritisation +An sf dataframe of Planning Units for spatial prioritization } \keyword{datasets} diff --git a/man/dat_mpas.Rd b/man/dat_mpas.Rd index a6d627a7..0f25c0d4 100644 --- a/man/dat_mpas.Rd +++ b/man/dat_mpas.Rd @@ -3,7 +3,7 @@ \docType{data} \name{dat_mpas} \alias{dat_mpas} -\title{MPA Data} +\title{Marine Protected Areas (MPAs) Data} \format{ \code{dat_mpas} A data frame with XXXX rows and XXX columns: @@ -20,6 +20,6 @@ A data frame with XXXX rows and XXX columns: dat_mpas } \description{ -An sf dataframe of planning units for spatial prioritisation +An sf dataframe of Planning Units for spatial prioritization } \keyword{datasets} diff --git a/man/dat_region.Rd b/man/dat_region.Rd index 3e551ec2..1772b1f4 100644 --- a/man/dat_region.Rd +++ b/man/dat_region.Rd @@ -19,6 +19,6 @@ A data frame with XXXX rows and XXX columns: dat_region } \description{ -An sf dataframe of planning units for spatial prioritisation +An sf dataframe of Planning Units for spatial prioritization } \keyword{datasets} diff --git a/man/dat_species_bin.Rd b/man/dat_species_bin.Rd index fde343e9..e1517de4 100644 --- a/man/dat_species_bin.Rd +++ b/man/dat_species_bin.Rd @@ -19,6 +19,6 @@ A data frame with XXXX rows and XXX columns: dat_species_bin } \description{ -An sf dataframe of planning units for spatial prioritisation +An sf dataframe of Planning Units for spatial prioritization } \keyword{datasets} diff --git a/man/dat_species_bin2.Rd b/man/dat_species_bin2.Rd index 1b2b77eb..23fe2e46 100644 --- a/man/dat_species_bin2.Rd +++ b/man/dat_species_bin2.Rd @@ -19,6 +19,6 @@ A data frame with XXXX rows and XXX columns: dat_species_bin2 } \description{ -An sf dataframe of planning units for spatial prioritisation +An sf dataframe of Planning Units for spatial prioritization } \keyword{datasets} diff --git a/man/dat_species_prob.Rd b/man/dat_species_prob.Rd index 6628ce45..cce28320 100644 --- a/man/dat_species_prob.Rd +++ b/man/dat_species_prob.Rd @@ -19,6 +19,6 @@ A data frame with XXXX rows and XXX columns: dat_species_prob } \description{ -An sf dataframe of planning units for spatial prioritisation +An sf dataframe of Planning Units for spatial prioritization } \keyword{datasets} diff --git a/man/splnr_climate_featureApproach.Rd b/man/splnr_climate_featureApproach.Rd index 24d3be1f..40f83edc 100644 --- a/man/splnr_climate_featureApproach.Rd +++ b/man/splnr_climate_featureApproach.Rd @@ -18,7 +18,7 @@ splnr_climate_featureApproach( distribution data).} \item{metric}{An \code{sf} object containing climate metric information. It must -have a column named 'metric' with the climate metric values per planning unit.} +have a column named 'metric' with the climate metric values per Planning Unit.} \item{targets}{A \code{data.frame} with two columns: \code{feature} (character, listing the original feature names) and \code{target} (numeric, the initial conservation @@ -41,7 +41,7 @@ assigned to the overall climate-smart layer. Defaults to \code{0.3} (30\%).} A \code{list} with two components: \itemize{ \item \code{Features}: An \code{sf} object containing the binary information per -planning unit for each original feature, plus the new \code{climate_layer} +Planning Unit for each original feature, plus the new \code{climate_layer} feature. This is ready to be passed to \code{prioritizr}. \item \code{Targets}: A \code{data.frame} with the adjusted targets for all features, including the \code{climate_layer}. This is also ready for \code{prioritizr}. diff --git a/man/splnr_climate_percentileApproach.Rd b/man/splnr_climate_percentileApproach.Rd index d3f93d58..1b358390 100644 --- a/man/splnr_climate_percentileApproach.Rd +++ b/man/splnr_climate_percentileApproach.Rd @@ -17,7 +17,7 @@ splnr_climate_percentileApproach( distribution data).} \item{metric}{An \code{sf} object containing climate metric information. It must -have a column named 'metric' with the climate metric values per planning unit.} +have a column named 'metric' with the climate metric values per Planning Unit.} \item{targets}{A \code{data.frame} with two columns: \code{feature} (character, listing the original feature names) and \code{target} (numeric, the initial conservation @@ -37,7 +37,7 @@ determining whether an area is a climate priority area or not. This is applied A \code{list} with two components: \itemize{ \item \code{Features}: An \code{sf} object containing the binary information per -planning unit for each feature, now filtered to include only its +Planning Unit for each feature, now filtered to include only its climate-smart occurrences. This is ready to be passed to \code{prioritizr}. \item \code{Targets}: A \code{data.frame} with the adjusted targets for the filtered features. This is also ready for \code{prioritizr}. diff --git a/man/splnr_climate_priorityAreaApproach.Rd b/man/splnr_climate_priorityAreaApproach.Rd index fc272ec6..918a9862 100644 --- a/man/splnr_climate_priorityAreaApproach.Rd +++ b/man/splnr_climate_priorityAreaApproach.Rd @@ -17,10 +17,10 @@ splnr_climate_priorityAreaApproach( \item{features}{An \code{sf} object representing conservation features (e.g., species distribution data). Each column (excluding geometry) should typically be a binary representation of a feature's presence (1) or absence (0) in each -planning unit.} +Planning Unit.} \item{metric}{An \code{sf} object containing climate metric information. It must -have a column named 'metric' with the climate metric values per planning unit.} +have a column named 'metric' with the climate metric values per Planning Unit.} \item{targets}{A \code{data.frame} with two columns: \code{feature} (character, listing the original feature names) and \code{target} (numeric, the initial conservation @@ -44,7 +44,7 @@ assigned specifically to climate-smart areas (refugia). Defaults to \code{1} (10 A \code{list} with two components: \itemize{ \item \code{Features}: An \code{sf} object containing the binary information per -planning unit for each feature, now split into \verb{_CS} (climate-smart) +Planning Unit for each feature, now split into \verb{_CS} (climate-smart) and \verb{_NCS} (non-climate-smart) components. This is ready to be passed to \code{prioritizr} when creating a conservation problem. \item \code{Targets}: A \code{data.frame} with the adjusted targets for the diff --git a/man/splnr_get_distCoast.Rd b/man/splnr_get_distCoast.Rd index f4fce317..7cb464e2 100644 --- a/man/splnr_get_distCoast.Rd +++ b/man/splnr_get_distCoast.Rd @@ -8,7 +8,7 @@ splnr_get_distCoast(dat_sf, custom_coast = NULL, res = "medium") } \arguments{ \item{dat_sf}{\verb{[sf]} \cr An \code{sf} object containing polygon or point features -representing the planning units. Must have a valid CRS.} +representing the Planning Units. Must have a valid CRS.} \item{custom_coast}{\verb{[sf]} \cr An optional \code{sf} object representing a custom coastline. If \code{NULL} (the default), the coastline is downloaded @@ -25,7 +25,7 @@ kilometers. } \description{ This function calculates the shortest distance from the centroid of each -planning unit in an \code{sf} object to the nearest coastline. It can use either +Planning Unit in an \code{sf} object to the nearest coastline. It can use either a default coastline from the \code{rnaturalearth} package or a custom-provided coastline \code{sf} object. } diff --git a/man/splnr_get_selFreq.Rd b/man/splnr_get_selFreq.Rd index 4a6e567c..8740f0cd 100644 --- a/man/splnr_get_selFreq.Rd +++ b/man/splnr_get_selFreq.Rd @@ -19,10 +19,10 @@ column named \code{solution_1}.} \value{ An \code{sf} object (\code{selFreq}) containing a column named \code{selFreq}. This column is a factor representing the selection frequency (sum of -selected occurrences across all solutions) for each planning unit. +selected occurrences across all solutions) for each Planning Unit. } \description{ -\code{splnr_get_selFreq()} calculates how many times each planning unit is +\code{splnr_get_selFreq()} calculates how many times each Planning Unit is selected across an array of \code{prioritizr} solutions. This "selection frequency" can be derived from either a list of individual solutions or a \code{prioritizr} portfolio object. @@ -43,7 +43,7 @@ object representing a single \code{prioritizr} solution (each with a "solution_1" column). } For both types, the function sums the binary \code{solution} values (0 or 1) -across all solutions for each planning unit. The result is converted to a +across all solutions for each Planning Unit. The result is converted to a factor to represent discrete frequency levels. The output \code{sf} object can then be passed to \code{splnr_plot_selectionFreq()} diff --git a/man/splnr_gg_add.Rd b/man/splnr_gg_add.Rd index e60a2f8d..11a0f449 100644 --- a/man/splnr_gg_add.Rd +++ b/man/splnr_gg_add.Rd @@ -2,7 +2,7 @@ % Please edit documentation in R/splnr_gg_add.R \name{splnr_gg_add} \alias{splnr_gg_add} -\title{Add-ons for Plotting \code{spatialplanr} Maps} +\title{Add-ons for Plotting \code{spatialplanr} Solution Maps} \usage{ splnr_gg_add( PUs = NULL, @@ -21,19 +21,26 @@ splnr_gg_add( lockIn = NULL, typeLockIn = "Full", nameLockIn = NULL, - alphaLockIn = 0.5, + alphaLockIn = 1, colorLockIn = "black", legendLockIn = "", labelLockIn = "MPAs", + lockOut = NULL, + typeLockOut = "Full", + nameLockOut = NULL, + alphaLockOut = 1, + colorLockOut = "black", + legendLockOut = "", + labelLockOut = "", ggtheme = "Default" ) } \arguments{ -\item{PUs}{An \code{sf} object representing planning units. If provided, their +\item{PUs}{An \code{sf} object representing Planning Units. If provided, their outlines will be drawn. Defaults to \code{NULL}.} \item{colorPUs}{A character string specifying the color for the outlines of the -planning units. Defaults to \code{"grey80"}.} +Planning Units. Defaults to \code{"grey80"}.} \item{Bndry}{An \code{sf} object representing the main planning region boundaries. If provided, its outline will be drawn. Defaults to \code{NULL}.} @@ -64,11 +71,11 @@ lines. Up to 6 categories are supported. Defaults to \code{NULL}.} Defaults to \code{"black"}.} \item{cropOverlay}{An \code{sf} object. Its bounding box will be used to set the -\code{xlim} and \code{ylim} of the \code{ggplot2::coord_sf} layer, effectively cropping the view. +\code{xlim} and \code{ylim} of the \code{ggplot2::coord_sf()} layer, effectively cropping the view. Defaults to \code{NULL}.} -\item{lockIn}{An \code{sf} object representing 'locked-in' areas (e.g., existing -Marine Protected Areas) that are fixed in a conservation prioritization. +\item{lockIn}{An \code{sf} object representing locked-in areas (e.g., existing +Marine Protected Areas (MPAs)) that are fixed in a conservation prioritization. Defaults to \code{NULL}.} \item{typeLockIn}{A character string specifying how \code{lockIn} areas should be @@ -80,7 +87,7 @@ data frame that contains binary (0/1 or TRUE/FALSE) information indicating locked-in status. Required if \code{lockIn} is not \code{NULL}.} \item{alphaLockIn}{A numeric value (0 to 1) for the opacity of the \code{lockIn} -areas when \code{typeLockIn} is \code{"Full"}. Defaults to \code{0.5}.} +areas when \code{typeLockIn} is \code{"Full"}. Defaults to \code{1}.} \item{colorLockIn}{A character string specifying the color for the \code{lockIn} areas. Defaults to \code{"black"}.} @@ -91,6 +98,30 @@ Can be an empty string \code{""} to suppress the title. Defaults to \code{""}.} \item{labelLockIn}{A character string for the legend label of the \code{lockIn} areas (e.g., "MPAs"). Defaults to \code{"MPAs"}.} +\item{lockOut}{An \code{sf} object representing locked-out areas (e.g., shipping lanes, +oil and gas leases, or other excluded zones) that must not be selected in a +conservation prioritization. Defaults to \code{NULL}.} + +\item{typeLockOut}{A character string specifying how \code{lockOut} areas should be +plotted. Can be \code{"Full"} (fills the areas with \code{colorLockOut}) or \code{"Contours"} +(draws only the outlines of the areas). Defaults to \code{"Full"}.} + +\item{nameLockOut}{A character string specifying the column name in the \code{lockOut} +data frame that contains binary (0/1 or TRUE/FALSE) information indicating +locked-out status. Required if \code{lockOut} is not \code{NULL}.} + +\item{alphaLockOut}{A numeric value (0 to 1) for the opacity of the \code{lockOut} +areas when \code{typeLockOut} is \code{"Full"}. Defaults to \code{1}.} + +\item{colorLockOut}{A character string specifying the color for the \code{lockOut} areas. +Defaults to \code{"black"}.} + +\item{legendLockOut}{A character string for the title of the \code{lockOut} legend. +Can be an empty string \code{""} to suppress the title. Defaults to \code{""}.} + +\item{labelLockOut}{A character string for the legend label of the \code{lockOut} areas +(e.g., "Shipping Lanes"). Defaults to \code{""}.} + \item{ggtheme}{The \code{ggplot2} theme to apply. Can be: \itemize{ \item \code{NA} or \code{FALSE}: No theme is applied, using \code{ggplot2} defaults. @@ -105,16 +136,18 @@ A \code{list} of \code{ggplot2} layers and theme elements that can be added to an existing \code{ggplot} object using \code{+}. } \description{ -This function allows users to customize existing \code{ggplot2} maps, particularly -those produced by other \code{spatialplanr} spatial plotting functions. It provides -options to add various spatial layers and apply consistent theming in a +This function allows users to customize existing \code{ggplot2} solution maps produced +by \code{spatialplanr} spatial plotting functions (e.g., \code{splnr_plot_solution()}). It +provides options to add various spatial layers and apply consistent theming in a simple and reproducible manner. } \details{ -The \code{splnr_gg_add} function enhances \code{ggplot2} objects by layering additional -spatial data such as planning unit outlines, study area boundaries, general -overlays, geographical contours, and 'locked-in' areas (e.g., existing protected -areas in a conservation prioritization). It offers fine-grained control over +The \code{splnr_gg_add()} function enhances \code{ggplot2} objects by layering additional +spatial data such as Planning Unit outlines, study area boundaries, general +overlays, geographical contours, locked-in areas (e.g., existing Marine Protected +Areas (MPAs) that must be included in a conservation prioritization), and +locked-out areas (e.g., areas that must be excluded from selection such as +shipping lanes or oil and gas leases). It offers fine-grained control over colors, opacities, and legend appearance for each added layer. When using \code{contours}, the input \code{sf} object is expected to have a column @@ -130,7 +163,7 @@ all theme elements manually. \examples{ \dontrun{ # Assuming 'dat_species_bin' and 'dat_PUs' are existing sf objects -# in your package, suitable for prioritisation problems and plotting. +# in your package, suitable for prioritization problems and plotting. # Create a dummy prioritizr problem and solve it for demonstration. dat_problem <- prioritizr::problem( @@ -146,13 +179,13 @@ dat_problem <- prioritizr::problem( dat_soln <- dat_problem \%>\% prioritizr::solve.ConservationProblem() -# Basic plot of the solution with default planning unit outlines and theme. +# Basic plot of the solution with default Planning Unit outlines and theme. plot_basic <- splnr_plot_solution(dat_soln) + splnr_gg_add(PUs = dat_PUs, ggtheme = "Default") print(plot_basic) # Example with boundary, a custom overlay, and locked-in areas shown as contours. -# For this example, let's create dummy `bndry_sf` and `locked_in_sf` based on `dat_PUs` +# For this example, let's create dummy `bndry_sf` and `locked_in_sf` based on `dat_PUs`. # In a real scenario, these would be loaded from your package or data. bndry_sf <- sf::st_union(dat_PUs) \%>\% sf::st_as_sf() locked_in_sf <- dat_PUs[1:100, ] \%>\% dplyr::mutate(is_mpa = 1) @@ -164,7 +197,6 @@ plot_custom <- splnr_plot_solution(dat_soln) + colorBndry = "darkblue", overlay = bndry_sf, # Using boundary as an example overlay colorOverlay = "lightblue", - alphaOverlay = 0.3, lockIn = locked_in_sf, typeLockIn = "Contours", nameLockIn = "is_mpa", diff --git a/man/splnr_plot.Rd b/man/splnr_plot.Rd index ecb802ac..5d7f0451 100644 --- a/man/splnr_plot.Rd +++ b/man/splnr_plot.Rd @@ -29,7 +29,7 @@ splnr_plot( an \code{sf} object and include a geometry column.} \item{colNames}{A character vector of column names from \code{df} to be used for -coloring the plot. If \code{NULL} (default), only the planning unit outlines are plotted. +coloring the plot. If \code{NULL} (default), only the Planning Unit outlines are plotted. If a single column is specified, it checks for binary, logical, or continuous data. If multiple columns are specified, it sums the values across these columns to create a "FeatureSum" for plotting.} @@ -66,7 +66,7 @@ the planning unit outlines. This function provides a versatile way to plot spatial data (\code{sf} objects) within the \code{spatialplanr} package. It can visualize various data types, including binary presence/absence, logical values, continuous data, or simply -the planning unit outlines. +the Planning Unit outlines. } \details{ The \code{splnr_plot} function automatically detects the type of data specified by @@ -83,11 +83,11 @@ workflow within the package. Written by Kilian Barreiro and Jason Everett. Last modified: February 2024. -The \code{splnr_plot} function automatically detects the type of data specified by +The \code{splnr_plot()} function automatically detects the type of data specified by \code{colNames} (binary, logical, or continuous) and adjusts the plotting aesthetics accordingly. If multiple \code{colNames} are provided, it calculates -the sum of features for each planning unit and plots this sum. If \code{colNames} -is \code{NULL}, it will simply plot the outlines of the planning units. +the sum of features for each Planning Unit and plots this sum. If \code{colNames} +is \code{NULL}, it will simply plot the outlines of the Planning Units. This function is designed to be a flexible replacement for several plotting functions, such as \code{splnr_plot_cost()}, \code{splnr_plot_binFeature()}, diff --git a/man/splnr_plot_climKernelDensity.Rd b/man/splnr_plot_climKernelDensity.Rd index b3194920..32bd2431 100644 --- a/man/splnr_plot_climKernelDensity.Rd +++ b/man/splnr_plot_climKernelDensity.Rd @@ -6,7 +6,8 @@ \usage{ splnr_plot_climKernelDensity( soln, - names = NA, + solution_names = "solution_1", + climate_names = "metric", type = "Normal", colorMap = "C", legendTitle = expression(" °C y"^"-1" * ""), @@ -19,10 +20,12 @@ splnr_plot_climKernelDensity( a \code{solution_1} column. For \code{type = "Basic"}: A single \code{prioritizr} solution \code{sf} object.} -\item{names}{A character vector of names corresponding to each solution in +\item{solution_names}{A character vector of names corresponding to each solution in \code{soln} when \code{type = "Normal"}. Not used for \code{type = "Basic"}. Defaults to \code{NA}.} +\item{climate_names}{A character string of the name of the climate} + \item{type}{A character string specifying the plotting style. Must be either \code{"Normal"} or \code{"Basic"}. Defaults to \code{"Normal"}.} @@ -59,7 +62,7 @@ style is streamlined for clarity and quick interpretation, ideal for stakeholder engagement. Both underlying functions require a \code{prioritizr} solution containing a -\code{metric} column with climate metric information and a \code{solution_1} column +climate metric column with climate metric information and a prioritizr solution column indicating selected planning units. } \examples{ @@ -110,7 +113,7 @@ print(plot_basic_kde) # Example 2: Normal (Fancy) kernel density plot for a single solution plot_normal_kde_single <- splnr_plot_climKernelDensity( soln = list(dat_solnClim), - names = c("Solution 1"), + solution_names = c("Solution 1"), type = "Normal" ) print(plot_normal_kde_single) @@ -122,7 +125,8 @@ dat_solnClim_2 <- dat_solnClim \%>\% plot_normal_kde_multi <- splnr_plot_climKernelDensity( soln = list(dat_solnClim, dat_solnClim_2), - names = c("Solution A", "Solution B"), + solution_names = c("Solution A", "Solution B"), + climate_names = "metric", type = "Normal", colorMap = "plasma", legendTitle = "Climate Value", diff --git a/man/splnr_plot_comparison.Rd b/man/splnr_plot_comparison.Rd index a00a8135..d66c58cf 100644 --- a/man/splnr_plot_comparison.Rd +++ b/man/splnr_plot_comparison.Rd @@ -26,7 +26,7 @@ A \code{ggplot} object representing the spatial comparison of the two solutions. \description{ The \code{splnr_plot_comparison()} function spatially visualizes the differences between two \code{prioritizr} conservation solutions. This helps in understanding -which planning units are common, added, or removed between two scenarios. +which Planning Units are common, added, or removed between two scenarios. } \details{ Conservation planning often involves comparing outputs from different @@ -35,7 +35,7 @@ by requiring two \code{sf} objects, \code{soln1} and \code{soln2}, each represen \code{prioritizr} solution and containing a \code{solution_1} column (binary, indicating selected vs. not selected). -The function categorizes planning units into "Same" (selected in both), +The function categorizes Planning Units into "Same" (selected in both), "Added (+)" (selected in \code{soln2} but not \code{soln1}), and "Removed (-)" (selected in \code{soln1} but not \code{soln2}). It then plots these categories with distinct colors for clear visualization. The output is a \code{ggplot} object diff --git a/man/splnr_plot_costOverlay.Rd b/man/splnr_plot_costOverlay.Rd index 79f16997..11da0f0d 100644 --- a/man/splnr_plot_costOverlay.Rd +++ b/man/splnr_plot_costOverlay.Rd @@ -16,7 +16,7 @@ splnr_plot_costOverlay( \item{soln}{The \code{prioritizr} solution object, expected as an \code{sf} object, containing at least a \code{solution_1} column.} -\item{cost}{An \code{sf} object containing the cost data for planning units. +\item{cost}{An \code{sf} object containing the cost data for Planning Units. If the \code{prioritizr} solution \code{soln} already contains the cost column specified by \code{costName}, this parameter can be \code{NA} (default). Otherwise, provide an \code{sf} object with the cost data.} @@ -34,18 +34,18 @@ Defaults to \code{"Solution overlaid with cost"}.} A \code{ggplot} object representing the solution with cost overlay. } \description{ -The \code{splnr_plot_costOverlay()} function visualizes the cost of each planning -unit overlaid on the solution of a \code{prioritizr} conservation problem. This +The \code{splnr_plot_costOverlay()} function visualizes the cost of each Planning +Unit overlaid on the solution of a \code{prioritizr} conservation problem. This allows for a customizable \code{ggplot2} visualization, highlighting the costs -within selected planning units. +within selected Planning Units. } \details{ This function requires a \code{prioritizr} solution as an \code{sf} object, which must contain a \code{solution_1} column indicating selected (1) or unselected (0) -planning units. It also requires a cost column, either present within the +Planning Units. It also requires a cost column, either present within the \code{soln} object or provided separately via the \code{Cost} parameter. -The function filters the solution to show only the selected planning units +The function filters the solution to show only the selected Planning Units and then overlays these with a gradient representing the cost. This output is a \code{ggplot} object that can be further customized using \code{splnr_gg_add()}. } diff --git a/man/splnr_plot_importanceScore.Rd b/man/splnr_plot_importanceScore.Rd index 4f965be7..7d09828a 100644 --- a/man/splnr_plot_importanceScore.Rd +++ b/man/splnr_plot_importanceScore.Rd @@ -42,11 +42,11 @@ A \code{ggplot} object representing the plot of importance scores. } \description{ The \code{splnr_plot_importanceScore()} function visualizes the importance scores -(irreplaceability) of planning units from a \code{prioritizr} conservation problem +(irreplaceability) of Planning Units from a \code{prioritizr} conservation problem using \code{ggplot2}. It supports different methods for calculating importance scores. } \details{ -Importance scores quantify the irreplaceability of a planning unit in a +Importance scores quantify the irreplaceability of a Planning Unit in a conservation solution. This function leverages the \code{prioritizr} package to calculate and plot three different types of importance scores: \itemize{ diff --git a/man/splnr_plot_selectionFreq.Rd b/man/splnr_plot_selectionFreq.Rd index 3030a676..66c05217 100644 --- a/man/splnr_plot_selectionFreq.Rd +++ b/man/splnr_plot_selectionFreq.Rd @@ -12,7 +12,7 @@ splnr_plot_selectionFreq( ) } \arguments{ -\item{selFreq}{An \code{sf} object containing the selection frequency data for planning units. +\item{selFreq}{An \code{sf} object containing the selection frequency data for Planning Units. This object must include a \code{selFreq} column (e.g., generated by \code{splnr_get_selFreq()}).} \item{plotTitle}{A character string for the title of the plot. Defaults to \code{""}.} @@ -26,20 +26,20 @@ Defaults to \code{"Greens"}.} Defaults to \code{"Selection \\nFrequency"}.} } \value{ -A \code{ggplot} object representing the plot of planning unit selection frequency. +A \code{ggplot} object representing the plot of Planning Unit selection frequency. } \description{ The \code{splnr_plot_selectionFreq()} function visualizes the selection frequency -of planning units across an array of \code{prioritizr} solutions. This is useful +of Planning Units across an array of \code{prioritizr} solutions. This is useful for understanding which areas are consistently selected as important for conservation. } \details{ When multiple spatial plans are generated (either from solutions to different conservation problems or via a \code{prioritizr} portfolio approach), it's -valuable to assess the robustness of planning unit selection. This function +valuable to assess the robustness of Planning Unit selection. This function takes an \code{sf} object as input, which must contain a \code{selFreq} column -representing the selection frequency of each planning unit. This \code{selFreq} +representing the selection frequency of each Planning Unit. This \code{selFreq} column can be generated using the \code{spatialplanr} function \code{splnr_get_selFreq()}. The function uses \code{ggplot2} to create a spatial plot of these frequencies, diff --git a/man/splnr_plot_solution.Rd b/man/splnr_plot_solution.Rd index 7ff5167c..b544818b 100644 --- a/man/splnr_plot_solution.Rd +++ b/man/splnr_plot_solution.Rd @@ -55,7 +55,7 @@ problems). It outputs a \code{ggplot} object, which can be further customized by combining it with the \code{spatialplanr} function \code{splnr_gg_add()}. For multi-zone problems (\code{zones = TRUE}), the function sums the selected -zones for each planning unit and plots the resulting combined selection. +zones for each Planning Unit and plots the resulting combined selection. The \code{colorVals} and \code{legendLabels} should be provided to match the number of selection levels (e.g., "Not selected", "Zone 1", "Zone 2", etc.). } diff --git a/man/splnr_replace_NAs.Rd b/man/splnr_replace_NAs.Rd index 7cd9a62c..9403d3de 100644 --- a/man/splnr_replace_NAs.Rd +++ b/man/splnr_replace_NAs.Rd @@ -25,8 +25,8 @@ of an \code{sf} dataframe with the value from the nearest spatial neighbor. } \details{ This function is useful for imputing missing data in spatial contexts. -It identifies all planning units with \code{NA} values in the \code{vari} column. -For each of these, it finds the geographically closest planning unit that +It identifies all Planning Units with \code{NA} values in the \code{vari} column. +For each of these, it finds the geographically closest Planning Unit that \emph{does not} have an \code{NA} value in \code{vari}, and then copies that non-missing value. This approach leverages the spatial autocorrelation often present in environmental and species data. diff --git a/man/splnr_targets_byInverseArea.Rd b/man/splnr_targets_byInverseArea.Rd index 49203cec..014fd433 100644 --- a/man/splnr_targets_byInverseArea.Rd +++ b/man/splnr_targets_byInverseArea.Rd @@ -9,7 +9,7 @@ splnr_targets_byInverseArea(df, target_min, target_max) \arguments{ \item{df}{An \code{sf} dataframe containing the features (e.g., species distribution data) for which to calculate inverse area targets. Each column (excluding -geometry) should represent a feature, and each row a planning unit.} +geometry) should represent a feature, and each row a Planning Unit.} \item{target_min}{A numeric value between 0 and 1 (inclusive) specifying the minimum target percentage. This will be the target for the most widespread feature.} @@ -35,10 +35,10 @@ range-restricted features. The calculation proceeds as follows: \enumerate{ -\item The area of a single planning unit is determined. +\item The area of a single Planning Unit is determined. \item The total area of the study region is estimated by multiplying the number -of planning units by the individual planning unit area. -\item For each feature (species), its total area across all planning units is +of Planning Units by the individual Planning Unit area. +\item For each feature (species), its total area across all Planning Units is calculated. \item The target for each feature is then scaled between \code{target_min} and \code{target_max} such that features with smaller areas receive targets closer @@ -48,7 +48,7 @@ to \code{target_min}. The input \code{df} is expected to be an \code{sf} object where columns (excluding geometry) represent different features (e.g., species presence/absence) and -rows represent planning units. +rows represent Planning Units. } \examples{ \dontrun{ diff --git a/tests/testthat/test-splnr_plotting_climate.R b/tests/testthat/test-splnr_plotting_climate.R index e10c3a2f..b74c5ddb 100644 --- a/tests/testthat/test-splnr_plotting_climate.R +++ b/tests/testthat/test-splnr_plotting_climate.R @@ -47,7 +47,7 @@ testthat::test_that("Correct function output", { testthat::test_that("Correct function output", { expect_s3_class( - splnr_plot_climKernelDensity(soln = list(dat_solnClim), names = c("Input 1"), type = "Normal") + splnr_plot_climKernelDensity(soln = list(dat_solnClim), type = "Normal") , "gg") }) diff --git a/vignettes/ClimateSmart.Rmd b/vignettes/ClimateSmart.Rmd index 5ca351b0..d18f0c78 100644 --- a/vignettes/ClimateSmart.Rmd +++ b/vignettes/ClimateSmart.Rmd @@ -243,7 +243,8 @@ However, we are also interested how climate-smart the selected planning units in ```{r, fig.width = 9} (ggClimDens <- splnr_plot_climKernelDensity( soln = list(dat_solnClim), - names = c("Input 1"), type = "Normal", + # names = c("Input 1"), + type = "Normal", legendTitle = "Climate velocity (add unit)", xAxisLab = "Climate velocity" )) @@ -283,7 +284,7 @@ targets <- Percentile_Approach$Targets ``` -We now add other information required to perform the spatial planning, such as the cost, and extract the names of all used features to then run a prioritisation. +We now add other information required to perform the spatial planning, such as the cost, and extract the names of all used features to then run a prioritization. ```{r, warning=FALSE} out_sf$Cost_None <- rep(1, 397) @@ -323,7 +324,8 @@ However, we are also interested how climate-smart the selected planning units in ```{r, fig.width = 9} (ggClimDens <- splnr_plot_climKernelDensity( soln = list(dat_solnClimPercentile), - names = c("Input 1"), type = "Normal", + # names = c("Input 1"), + type = "Normal", legendTitle = "Climate velocity (add unit)", xAxisLab = "Climate velocity" )) @@ -359,10 +361,10 @@ targets <- Feature_Approach$Targets ``` -We now add other information required to perform the spatial planning, such as the cost, and extract the names of all used features to then run a prioritisation. +We now add other information required to perform the spatial planning, such as the cost, and extract the names of all used features to then run a prioritization. ```{r} -out_sf$Cost_None <- rep(1, 397) +out_sf$Cost_None <- 1 usedFeatures <- out_sf %>% sf::st_drop_geometry() %>% @@ -395,7 +397,8 @@ However, we are also interested how climate-smart the selected planning units in ```{r, fig.width = 9} (ggClimDens <- splnr_plot_climKernelDensity( soln = list(dat_solnClimFeature), - names = c("Input 1"), type = "Normal", + # names = c("Input 1"), + type = "Normal", legendTitle = "Climate velocity (add unit)", xAxisLab = "Climate velocity" )) diff --git a/vignettes/GlobalFishingWatch.Rmd b/vignettes/GlobalFishingWatch.Rmd index 9355186f..98fa2616 100644 --- a/vignettes/GlobalFishingWatch.Rmd +++ b/vignettes/GlobalFishingWatch.Rmd @@ -63,19 +63,14 @@ _(You could be asked to restart R for changes to take effect.)_ usethis::edit_r_environ() ``` -We save the key in an object that will be used in gfwr functions. -```{r, eval=FALSE} -key <- gfwr::gfw_auth() -``` - ## Fishing effort visualization A region_id is necessary to use the `get_raster` function. ```{r, results='hide'} -region_id <- gfwr::get_region_id(region_name = "Australia", +region_id <- get_region_id(region = "Australia", region_source = "EEZ", - key = gfwr::gfw_auth())$id + key = gfwr::gfw_auth())$id[2] ``` The `get_raster` function gets a raster of fishing effort from the API and @@ -90,7 +85,7 @@ Data can be provided through :
- `VESSEL_ID`, `FLAG`, `GEARTYPE`, `FLAGANDGEARTYPE`. ```{r, eval=FALSE, message=FALSE} -gfwr::get_raster( +get_raster( spatial_resolution = "LOW", temporal_resolution = "MONTHLY", group_by = "FLAGANDGEARTYPE", diff --git a/vignettes/MultipleUse.Rmd b/vignettes/MultipleUse.Rmd index fcee848b..149692ff 100644 --- a/vignettes/MultipleUse.Rmd +++ b/vignettes/MultipleUse.Rmd @@ -128,7 +128,7 @@ col_name <- spDataFiltered %>% ### Spatial planning including zones -So far, all steps were exactly the same as in a spatial plan that does not include zones. To have a direct comparison, we will first run a spatial plan that does not include zoning. For this, we will define targets for our features (here: 30% for all features) and create a conservation problem where we include an area-based cost in our prioritisation. +So far, all steps were exactly the same as in a spatial plan that does not include zones. To have a direct comparison, we will first run a spatial plan that does not include zoning. For this, we will define targets for our features (here: 30% for all features) and create a conservation problem where we include an area-based cost in our prioritization. ```{r} target <- rep(0.3, nrow(Dict)) @@ -325,7 +325,7 @@ s3 <- p3 %>% prioritizr::solve.ConservationProblem() ``` -With `add_boundary_penalties()` we set a penalty of 0.5 between the zones we defined in `zm1`. For the purpose of this example, we also set a 10 second time limit for the prioritisation. The results show less fragmentation than in the previous solution without penalties: +With `add_boundary_penalties()` we set a penalty of 0.5 between the zones we defined in `zm1`. For the purpose of this example, we also set a 10 second time limit for the prioritization. The results show less fragmentation than in the previous solution without penalties: ```{r, fig.width=9} (gg_s3 <- splnr_plot_solution( @@ -431,7 +431,7 @@ mpas <- MPAsCoralSea %>% dplyr::filter(status == 1) ``` -We need to specify which zone the constraint should be applied to, give information on the planning unit identifier, rename the column of interest to "status" and filter out only the planning units that should be locked in. +We need to specify which zone the constraint should be applied to, give information on the Planning Unit identifier, rename the column of interest to "status" and filter out only the Planning Units that should be locked-in. ```{r} # NOTE: When using sf input, we need as many cost columns as we have zones @@ -830,7 +830,7 @@ print(r12) ### Next steps #### Short-term -* Test for run time of zones compared to a normal prioritisation +* Test for run time of zones compared to a normal prioritization * Communicate zones outcomes effectively (e.g. targets, cost overlay etc.) #### Longer-term diff --git a/vignettes/spatialplanr.Rmd b/vignettes/spatialplanr.Rmd index 029fc710..748e9da2 100644 --- a/vignettes/spatialplanr.Rmd +++ b/vignettes/spatialplanr.Rmd @@ -220,7 +220,7 @@ cells. To get a better idea of the overall distribution of the used features, we can also plot the number of features with suitable habitat within a -planning unit of the study region. +Planning Unit of the study region. ```{r} (ggFeatNo <- splnr_plot(df = datEx_species_bin, @@ -234,7 +234,7 @@ planning unit of the study region. )) ``` -## Prepare Data for prioritisation +## Prepare Data for prioritization For the spatial prioritization we also need to extract the names of our features to pass into `prioritizr`. @@ -444,7 +444,7 @@ legends <- c("Important", "Representative") ### Visualization of importance scores Importance scores can help to assess the relative importance of an -individual selected planning unit in the spatial plan (for more +individual selected Planning Unit in the spatial plan (for more information, see ) Here, we use two different importance scores, the Ferrier Score and @@ -575,9 +575,9 @@ datEx_soln2 <- datEx_problem2 %>% )) ``` -But we locked in areas that were already existing MPAs. If we want to -show the overlap between the selected planning units and the current -MPAs, we can can add this to the `splnr_gg_add()`function. +But we locked-in areas that were already existing Marine Protected Areas (MPAs). If we want to +show the overlap between the selected Planning Units and the current +MPAs, we can can add this to the `splnr_gg_add()` function. ```{r} (splnr_plot_solution(datEx_soln2) + @@ -589,8 +589,8 @@ MPAs, we can can add this to the `splnr_gg_add()`function. )) ``` -If we instead only want to see the contours of the locked in areas we -can set `typeLockIn = "Contours"`in `splnr_gg_add()`. +If we instead only want to see the contours of the locked-in areas we +can set `typeLockIn = "Contours"` in `splnr_gg_add()`. ```{r} (splnr_plot_solution(datEx_soln2) + @@ -634,7 +634,7 @@ correlation between solution 1 and solution 2. ### Plotting selection frequency Sometimes when multiple spatial plans are generated, we are interested -in how many times a planning unit is selected across the array of +in how many times a Planning Unit is selected across the array of solutions. To demonstrate how this can be done using this package, we first create an array (= portfolio) of solutions. One example of this is by using the portfolio From a7aaff83835f48f8ac525e39a87dc64be0b8257f Mon Sep 17 00:00:00 2001 From: Jason Everett Date: Tue, 18 Nov 2025 06:14:36 +1100 Subject: [PATCH 2/5] Misc clean up --- README.Rmd | 652 ++++----- README.md | 873 ++++++------ docs/404.html | 4 +- docs/404.md | 3 + docs/LICENSE-text.html | 4 +- docs/LICENSE-text.md | 4 + docs/LICENSE.html | 4 +- docs/LICENSE.md | 22 + docs/apple-touch-icon.png | Bin 34928 -> 29912 bytes docs/articles/ClimateSmart.html | 45 +- docs/articles/ClimateSmart.md | 479 +++++++ .../figure-html/unnamed-chunk-10-1.png | Bin 165894 -> 170939 bytes .../figure-html/unnamed-chunk-11-1.png | Bin 179363 -> 184721 bytes .../figure-html/unnamed-chunk-15-1.png | Bin 171813 -> 176444 bytes .../figure-html/unnamed-chunk-19-1.png | Bin 179299 -> 183675 bytes .../figure-html/unnamed-chunk-23-1.png | Bin 172044 -> 177121 bytes docs/articles/GlobalFishingWatch.html | 41 +- docs/articles/GlobalFishingWatch.md | 215 +++ .../figure-html/unnamed-chunk-10-1.png | Bin 0 -> 153771 bytes .../figure-html/unnamed-chunk-13-1.png | Bin 0 -> 179466 bytes .../figure-html/unnamed-chunk-15-1.png | Bin 0 -> 391960 bytes .../figure-html/unnamed-chunk-7-1.png | Bin 0 -> 242434 bytes .../figure-html/unnamed-chunk-8-1.png | Bin 158559 -> 187360 bytes docs/articles/MultipleUse.html | 56 +- docs/articles/MultipleUse.md | 1176 +++++++++++++++++ .../figure-html/unnamed-chunk-11-1.png | Bin 203198 -> 198798 bytes .../figure-html/unnamed-chunk-16-1.png | Bin 203271 -> 199907 bytes .../figure-html/unnamed-chunk-21-1.png | Bin 200945 -> 196439 bytes .../figure-html/unnamed-chunk-24-1.png | Bin 200263 -> 200596 bytes .../figure-html/unnamed-chunk-25-1.png | Bin 200810 -> 197201 bytes .../figure-html/unnamed-chunk-27-1.png | Bin 200257 -> 196553 bytes .../figure-html/unnamed-chunk-30-1.png | Bin 214972 -> 202089 bytes .../figure-html/unnamed-chunk-32-1.png | Bin 194223 -> 190553 bytes .../figure-html/unnamed-chunk-35-1.png | Bin 204872 -> 200392 bytes .../figure-html/unnamed-chunk-41-1.png | Bin 218991 -> 212499 bytes .../figure-html/unnamed-chunk-45-1.png | Bin 224184 -> 214262 bytes .../figure-html/unnamed-chunk-51-1.png | Bin 204867 -> 199486 bytes docs/articles/index.html | 4 +- docs/articles/index.md | 12 + docs/articles/spatialplanr.html | 110 +- docs/articles/spatialplanr.md | 702 ++++++++++ .../figure-html/unnamed-chunk-10-1.png | Bin 185616 -> 179339 bytes .../figure-html/unnamed-chunk-11-1.png | Bin 180105 -> 173201 bytes .../figure-html/unnamed-chunk-14-1.png | Bin 187340 -> 190774 bytes .../figure-html/unnamed-chunk-15-1.png | Bin 203220 -> 201550 bytes .../figure-html/unnamed-chunk-16-1.png | Bin 216404 -> 210780 bytes .../figure-html/unnamed-chunk-19-1.png | Bin 198081 -> 195046 bytes .../figure-html/unnamed-chunk-26-1.png | Bin 190566 -> 191105 bytes .../figure-html/unnamed-chunk-27-1.png | Bin 224562 -> 218149 bytes .../figure-html/unnamed-chunk-30-1.png | Bin 245890 -> 238675 bytes .../figure-html/unnamed-chunk-32-1.png | Bin 194387 -> 192099 bytes .../figure-html/unnamed-chunk-35-1.png | Bin 198479 -> 194268 bytes .../figure-html/unnamed-chunk-36-1.png | Bin 207011 -> 197554 bytes .../figure-html/unnamed-chunk-37-1.png | Bin 164636 -> 163667 bytes .../figure-html/unnamed-chunk-38-1.png | Bin 225480 -> 214284 bytes .../figure-html/unnamed-chunk-39-1.png | Bin 41597 -> 41716 bytes .../figure-html/unnamed-chunk-40-1.png | Bin 209746 -> 206767 bytes .../figure-html/unnamed-chunk-9-1.png | Bin 137599 -> 125391 bytes docs/authors.html | 8 +- docs/authors.md | 25 + docs/deps/bootstrap-5.3.1/bootstrap.min.css | 2 +- docs/favicon-96x96.png | Bin 0 -> 10185 bytes docs/favicon.ico | Bin 15086 -> 15086 bytes docs/favicon.svg | 3 + docs/index.html | 274 +++- docs/index.md | 22 + docs/katex-auto.js | 4 +- docs/lightswitch.js | 4 +- docs/llms.txt | 193 +++ docs/logo.png | Bin 67895 -> 68250 bytes docs/pkgdown.js | 192 +-- docs/pkgdown.yml | 6 +- docs/reference/CoralSeaVelocity.html | 4 +- docs/reference/CoralSeaVelocity.md | 25 + docs/reference/IUCN_IA_Targets.html | 4 +- docs/reference/IUCN_IA_Targets.md | 34 + docs/reference/MPAsCoralSea.html | 12 +- docs/reference/MPAsCoralSea.md | 22 + docs/reference/dat_PUs.html | 8 +- docs/reference/dat_PUs.md | 21 + docs/reference/dat_bathy.html | 4 +- docs/reference/dat_bathy.md | 25 + docs/reference/dat_bndry.html | 10 +- docs/reference/dat_bndry.md | 21 + docs/reference/dat_category.html | 6 +- docs/reference/dat_category.md | 25 + docs/reference/dat_category2.html | 6 +- docs/reference/dat_category2.md | 25 + docs/reference/dat_clim.html | 8 +- docs/reference/dat_clim.md | 25 + docs/reference/dat_mpas.html | 10 +- docs/reference/dat_mpas.md | 25 + docs/reference/dat_region.html | 8 +- docs/reference/dat_region.md | 21 + docs/reference/dat_species_bin.html | 8 +- docs/reference/dat_species_bin.md | 21 + docs/reference/dat_species_bin2.html | 8 +- docs/reference/dat_species_bin2.md | 21 + docs/reference/dat_species_prob.html | 8 +- docs/reference/dat_species_prob.md | 21 + .../figures/README-unnamed-chunk-13-1.png | Bin 0 -> 43452 bytes .../figures/README-unnamed-chunk-5-1.png | Bin 0 -> 41027 bytes .../figures/README-unnamed-chunk-6-1.png | Bin 0 -> 51874 bytes .../figures/README-unnamed-chunk-6-2.png | Bin 0 -> 37410 bytes .../figures/README-unnamed-chunk-7-1.png | Bin 0 -> 37104 bytes .../figures/README-unnamed-chunk-8-1.png | Bin 0 -> 40951 bytes .../figures/README-unnamed-chunk-9-1.png | Bin 0 -> 38994 bytes docs/reference/figures/logo.png | Bin 67895 -> 68250 bytes docs/reference/index.html | 238 ++-- docs/reference/index.md | 157 +++ docs/reference/pipe.html | 4 +- docs/reference/pipe.md | 9 + docs/reference/spDataFiltered.html | 4 +- docs/reference/spDataFiltered.md | 21 + docs/reference/spatialplanr-package.html | 8 +- docs/reference/spatialplanr-package.md | 25 + docs/reference/splnr_apply_cutoffs.html | 173 ++- docs/reference/splnr_apply_cutoffs.md | 201 +++ docs/reference/splnr_arrangeFeatures.html | 46 +- docs/reference/splnr_arrangeFeatures.md | 49 + .../splnr_climate_featureApproach.html | 89 +- .../splnr_climate_featureApproach.md | 123 ++ .../splnr_climate_percentileApproach.html | 86 +- .../splnr_climate_percentileApproach.md | 117 ++ .../splnr_climate_priorityAreaApproach.html | 91 +- .../splnr_climate_priorityAreaApproach.md | 129 ++ .../splnr_convert_regionalisation.html | 4 +- .../splnr_convert_regionalisation.md | 49 + docs/reference/splnr_convert_toPUs.html | 4 +- docs/reference/splnr_convert_toPUs.md | 38 + docs/reference/splnr_create_polygon.html | 59 +- docs/reference/splnr_create_polygon.md | 67 + docs/reference/splnr_featureNames.html | 58 +- docs/reference/splnr_featureNames.md | 65 + docs/reference/splnr_get_IUCNRedList.html | 123 +- docs/reference/splnr_get_IUCNRedList.md | 93 ++ docs/reference/splnr_get_MPAs.html | 94 +- docs/reference/splnr_get_MPAs.md | 115 ++ docs/reference/splnr_get_boundary.html | 80 +- docs/reference/splnr_get_boundary.md | 86 ++ docs/reference/splnr_get_distCoast.html | 105 +- docs/reference/splnr_get_distCoast.md | 80 ++ docs/reference/splnr_get_featureRep.html | 154 ++- docs/reference/splnr_get_featureRep.md | 204 +++ docs/reference/splnr_get_gfw.html | 100 +- docs/reference/splnr_get_gfw.md | 129 ++ docs/reference/splnr_get_kappaCorrData.html | 88 +- docs/reference/splnr_get_kappaCorrData.md | 101 ++ docs/reference/splnr_get_selFreq.html | 90 +- docs/reference/splnr_get_selFreq.md | 106 ++ docs/reference/splnr_gg_add.html | 225 +++- docs/reference/splnr_gg_add.md | 292 ++++ docs/reference/splnr_match_names.html | 69 +- docs/reference/splnr_match_names.md | 71 + docs/reference/splnr_plot.html | 246 +++- docs/reference/splnr_plot.md | 227 ++++ docs/reference/splnr_plot_MPAs.html | 4 +- docs/reference/splnr_plot_MPAs.md | 64 + docs/reference/splnr_plot_binFeature.html | 4 +- docs/reference/splnr_plot_binFeature.md | 69 + docs/reference/splnr_plot_circBplot.html | 54 +- docs/reference/splnr_plot_circBplot.md | 143 ++ docs/reference/splnr_plot_climData.html | 69 +- docs/reference/splnr_plot_climData.md | 88 ++ .../splnr_plot_climKernelDensity.html | 111 +- .../reference/splnr_plot_climKernelDensity.md | 156 +++ docs/reference/splnr_plot_comparison.html | 59 +- docs/reference/splnr_plot_comparison.md | 96 ++ docs/reference/splnr_plot_corrMat.html | 87 +- docs/reference/splnr_plot_corrMat.md | 120 ++ docs/reference/splnr_plot_cost.html | 14 +- docs/reference/splnr_plot_cost.md | 74 ++ docs/reference/splnr_plot_costOverlay.html | 82 +- docs/reference/splnr_plot_costOverlay.md | 103 ++ docs/reference/splnr_plot_featureNo.html | 4 +- docs/reference/splnr_plot_featureNo.md | 68 + docs/reference/splnr_plot_featureRep-1.png | Bin 56016 -> 56260 bytes docs/reference/splnr_plot_featureRep-2.png | Bin 0 -> 57965 bytes docs/reference/splnr_plot_featureRep-3.png | Bin 0 -> 65657 bytes docs/reference/splnr_plot_featureRep.html | 102 +- docs/reference/splnr_plot_featureRep.md | 164 +++ .../reference/splnr_plot_importanceScore.html | 83 +- docs/reference/splnr_plot_importanceScore.md | 127 ++ docs/reference/splnr_plot_selectionFreq.html | 69 +- docs/reference/splnr_plot_selectionFreq.md | 94 ++ docs/reference/splnr_plot_solution.html | 88 +- docs/reference/splnr_plot_solution.md | 140 ++ docs/reference/splnr_replace_NAs.html | 50 +- docs/reference/splnr_replace_NAs.md | 56 + docs/reference/splnr_scale_01.html | 49 +- docs/reference/splnr_scale_01.md | 61 + docs/reference/splnr_targets_byCategory.html | 62 +- docs/reference/splnr_targets_byCategory.md | 76 ++ docs/reference/splnr_targets_byIUCN.html | 92 +- docs/reference/splnr_targets_byIUCN.md | 109 ++ .../splnr_targets_byInverseArea.html | 65 +- docs/reference/splnr_targets_byInverseArea.md | 83 ++ docs/search.json | 2 +- docs/site.webmanifest | 21 + docs/web-app-manifest-192x192.png | Bin 0 -> 33537 bytes docs/web-app-manifest-512x512.png | Bin 0 -> 193587 bytes 201 files changed, 11508 insertions(+), 1921 deletions(-) create mode 100644 docs/404.md create mode 100644 docs/LICENSE-text.md create mode 100644 docs/LICENSE.md create mode 100644 docs/articles/ClimateSmart.md create mode 100644 docs/articles/GlobalFishingWatch.md create mode 100644 docs/articles/GlobalFishingWatch_files/figure-html/unnamed-chunk-10-1.png create mode 100644 docs/articles/GlobalFishingWatch_files/figure-html/unnamed-chunk-13-1.png create mode 100644 docs/articles/GlobalFishingWatch_files/figure-html/unnamed-chunk-15-1.png create mode 100644 docs/articles/GlobalFishingWatch_files/figure-html/unnamed-chunk-7-1.png create mode 100644 docs/articles/MultipleUse.md create mode 100644 docs/articles/index.md create mode 100644 docs/articles/spatialplanr.md create mode 100644 docs/authors.md create mode 100644 docs/favicon-96x96.png create mode 100644 docs/favicon.svg create mode 100644 docs/index.md create mode 100644 docs/llms.txt create mode 100644 docs/reference/CoralSeaVelocity.md create mode 100644 docs/reference/IUCN_IA_Targets.md create mode 100644 docs/reference/MPAsCoralSea.md create mode 100644 docs/reference/dat_PUs.md create mode 100644 docs/reference/dat_bathy.md create mode 100644 docs/reference/dat_bndry.md create mode 100644 docs/reference/dat_category.md create mode 100644 docs/reference/dat_category2.md create mode 100644 docs/reference/dat_clim.md create mode 100644 docs/reference/dat_mpas.md create mode 100644 docs/reference/dat_region.md create mode 100644 docs/reference/dat_species_bin.md create mode 100644 docs/reference/dat_species_bin2.md create mode 100644 docs/reference/dat_species_prob.md create mode 100644 docs/reference/figures/README-unnamed-chunk-13-1.png create mode 100644 docs/reference/figures/README-unnamed-chunk-5-1.png create mode 100644 docs/reference/figures/README-unnamed-chunk-6-1.png create mode 100644 docs/reference/figures/README-unnamed-chunk-6-2.png create mode 100644 docs/reference/figures/README-unnamed-chunk-7-1.png create mode 100644 docs/reference/figures/README-unnamed-chunk-8-1.png create mode 100644 docs/reference/figures/README-unnamed-chunk-9-1.png create mode 100644 docs/reference/index.md create mode 100644 docs/reference/pipe.md create mode 100644 docs/reference/spDataFiltered.md create mode 100644 docs/reference/spatialplanr-package.md create mode 100644 docs/reference/splnr_apply_cutoffs.md create mode 100644 docs/reference/splnr_arrangeFeatures.md create mode 100644 docs/reference/splnr_climate_featureApproach.md create mode 100644 docs/reference/splnr_climate_percentileApproach.md create mode 100644 docs/reference/splnr_climate_priorityAreaApproach.md create mode 100644 docs/reference/splnr_convert_regionalisation.md create mode 100644 docs/reference/splnr_convert_toPUs.md create mode 100644 docs/reference/splnr_create_polygon.md create mode 100644 docs/reference/splnr_featureNames.md create mode 100644 docs/reference/splnr_get_IUCNRedList.md create mode 100644 docs/reference/splnr_get_MPAs.md create mode 100644 docs/reference/splnr_get_boundary.md create mode 100644 docs/reference/splnr_get_distCoast.md create mode 100644 docs/reference/splnr_get_featureRep.md create mode 100644 docs/reference/splnr_get_gfw.md create mode 100644 docs/reference/splnr_get_kappaCorrData.md create mode 100644 docs/reference/splnr_get_selFreq.md create mode 100644 docs/reference/splnr_gg_add.md create mode 100644 docs/reference/splnr_match_names.md create mode 100644 docs/reference/splnr_plot.md create mode 100644 docs/reference/splnr_plot_MPAs.md create mode 100644 docs/reference/splnr_plot_binFeature.md create mode 100644 docs/reference/splnr_plot_circBplot.md create mode 100644 docs/reference/splnr_plot_climData.md create mode 100644 docs/reference/splnr_plot_climKernelDensity.md create mode 100644 docs/reference/splnr_plot_comparison.md create mode 100644 docs/reference/splnr_plot_corrMat.md create mode 100644 docs/reference/splnr_plot_cost.md create mode 100644 docs/reference/splnr_plot_costOverlay.md create mode 100644 docs/reference/splnr_plot_featureNo.md create mode 100644 docs/reference/splnr_plot_featureRep-2.png create mode 100644 docs/reference/splnr_plot_featureRep-3.png create mode 100644 docs/reference/splnr_plot_featureRep.md create mode 100644 docs/reference/splnr_plot_importanceScore.md create mode 100644 docs/reference/splnr_plot_selectionFreq.md create mode 100644 docs/reference/splnr_plot_solution.md create mode 100644 docs/reference/splnr_replace_NAs.md create mode 100644 docs/reference/splnr_scale_01.md create mode 100644 docs/reference/splnr_targets_byCategory.md create mode 100644 docs/reference/splnr_targets_byIUCN.md create mode 100644 docs/reference/splnr_targets_byInverseArea.md create mode 100644 docs/site.webmanifest create mode 100644 docs/web-app-manifest-192x192.png create mode 100644 docs/web-app-manifest-512x512.png diff --git a/README.Rmd b/README.Rmd index 0cef93cc..8fa7be76 100644 --- a/README.Rmd +++ b/README.Rmd @@ -13,7 +13,7 @@ knitr::opts_chunk$set( ) ``` -# spatialplanr spatialplanr websitespatialplanr website [![Lifecycle: experimental](https://img.shields.io/badge/lifecycle-experimental-orange.svg)](https://lifecycle.r-lib.org/articles/stages.html#experimental) @@ -26,7 +26,7 @@ knitr::opts_chunk$set( # Introduction to spatialplanr -Welcome to _spatialplanr_, an R package designed to streamline and enhance spatial conservation prioritization efforts by explicitly integrating climate change considerations. Building upon the powerful _prioritizr_ package, _spatialplanr_ provides a suite of tools for conservation planners to develop more robust and climate-resilient protected area networks. +Welcome to _spatialplanr_, an R package designed to streamline and enhance spatial conservation prioritization efforts by explicitly integrating climate change considerations. Building upon the powerful _prioritizr_ package, _spatialplanr_ provides a suite of tools for conservation planners to develop robust protected area networks. ## Installation @@ -37,335 +37,335 @@ Be aware that this package is in the very early stages of development. Functions devtools::install_github("https://github.com/SpatialPlanning/spatialplanr") ``` -# Purpose and Goals + -The escalating impacts of climate change necessitate a paradigm shift in how we approach conservation. Traditional conservation planning often focuses on static biodiversity patterns, which may not adequately account for the dynamic nature of species distributions and ecosystem processes under a changing climate. _spatialplanr_ aims to address this gap by: + -**Facilitating Climate-Smart Planning**: Providing functions that incorporate climate data directly into the planning process, allowing for the identification of areas critical for both biodiversity and resilience to future climate conditions. -Offering Diverse Methodological Approaches: Implementing multiple established climate-smart conservation planning frameworks (e.g., Climate Priority Areas, Climate Features, Climate Percentiles) to offer flexibility based on specific planning goals and data availability. + + -**Streamlining Workflow**: Offering end-to-end functionality, from data preprocessing and integration to advanced visualization of results, simplifying complex analytical tasks for users. + -**Enhancing Decision-Making**: Producing outputs that directly feed into spatial prioritization software like prioritizr, enabling the generation of optimal conservation solutions that balance biodiversity representation with climate resilience. -By using spatialplanr, practitioners can move beyond reactive conservation and proactively design protected area systems better equipped to safeguard biodiversity in a rapidly changing world. + + -# Core Climate-Smart Planning Approaches + -_spatialplanr_ implements several key approaches for integrating climate change into spatial prioritization, largely drawing inspiration from frameworks like that presented in Buenafe et al. (2023) "A metric‐based framework for climate‐smart conservation planning" (DOI: 10.1002/eap.2852). + -These approaches are designed to transform biodiversity features and conservation targets based on climate metrics, allowing for a more nuanced understanding of how climate change may impact conservation priorities. The main approaches included in _spatialplanr_ are: - * **Climate Priority Area (CPA) Approach**: Identifies climate-smart areas within the distribution of each conservation feature, creating new components for climate-smart and non-climate-smart areas. - * **Climate Feature Approach**: Treats climate-smart areas as a distinct conservation feature, allowing for explicit conservation targets on climate resilience. - * **Climate Percentile Approach**: Sets conservation targets based on percentile ranges of climate metrics, allowing for targeted protection of areas within specific climate resilience thresholds. + + + + -# Data Acquisition and Preprocessing Utilities -_spatialplanr_ also provides convenience functions for acquiring and preparing data, which can be crucial for climate-smart planning. - -```{r} -# Load spatialplanr -library(spatialplanr) -library(tidyverse) -``` - -1. Get IUCN Red List Data -Function: `splnr_get_IUCNRedList()` - -This function interfaces with the IUCN Red List API to retrieve conservation status information for a list of species. This data can be valuable for assigning species-specific targets (e.g., higher targets for more threatened species) or filtering species based on their conservation status. - -Note: Requires an IUCN Red List API token. - -```{r} -# # Example: Fetch IUCN data for a few marine species -# # Ensure your IUCN Red List API token is set: -# # Sys.setenv(IUCN_REDLIST_KEY = "YOUR_API_KEY") # Replace with your actual key -# -# # Example species list -# my_species <- c("Orcinus orca", "Chelonia mydas", "Thunnus thynnus") -# -# # Create a dataframe matching the expected input format -# species_df <- data.frame( -# scientific_name = my_species -# ) -# -# # Get IUCN data -# iucn_data <- splnr_get_IUCNRedList(df = species_df, species_col = "scientific_name") -# print(iucn_data) - -``` - -2. Get Global Fishing Watch (GFW) Data -Function: `splnr_get_gfw()` - -This function facilitates the retrieval of fishing activity data (e.g., apparent fishing hours) from Global Fishing Watch (GFW). GFW data can be used to inform cost layers (e.g., higher fishing effort areas might have higher opportunity costs for conservation) or as a proxy for human impact in planning units. - -Note: Requires a GFW API token. - -```{r} -# Example: Get yearly fishing hours for Australia EEZ - -gfw_data_aus <- splnr_get_gfw( - region = 'Australia', - start_date = "2021-01-01", - end_date = "2021-12-31", - temp_res = "YEARLY", - spat_res = "LOW", - region_source = "EEZ", - cCRS = "EPSG:4326", - compress = TRUE # Returns polygons aggregated by fishing hours -) -print(head(gfw_data_aus)) -``` - -## Visualization Tools -_spatialplanr_ offers a rich set of plotting functions to visualize input data, climate metrics, and most importantly, the outputs of your spatial prioritization analyses. These functions are built on ggplot2 and sf for high-quality spatial visualizations. - -1. Plot Climate Data -Function: `splnr_plot_climData()` - -Visualizes the spatial distribution of your climate metric, allowing you to quickly inspect patterns in climate velocity, temperature anomaly, or other relevant climate variables. - -```{r} -# Assuming 'dat_clim' from previous examples is available -# Plot the 'metric' column from dat_clim -splnr_plot_climData( - df = dat_clim, - colInterest = "metric", - plotTitle = "Example Climate Metric Distribution", - legendTitle = "Metric Value" -) -``` - -2. Plot Climate Kernel Density -Functions: `splnr_plot_climKernelDensity_Basic()`, `splnr_plot_climKernelDensity_Fancy()`, `splnr_plot_climKernelDensity()` - -These functions help visualize the distribution of climate metric values within selected planning units (e.g., a proposed protected area network) compared to the overall distribution. This helps assess if climate-smart areas are being adequately captured. - -`_Basic()`: Simple kernel density plot. -`_Fancy()`: More customizable kernel density plot, allowing multiple solutions and specific zones. -`_climKernelDensity()`: A wrapper function that selects between basic and fancy plots based on input type. - -```{r} -solution_df <- dat_clim %>% - dplyr::mutate( - solution_1 = sample(c(0, 1), size = dplyr::n(), replace = TRUE, prob = c(0.7, 0.3)), - metric_category = cut(metric, breaks = 3, labels = c("Low", "Medium", "High")) - ) - -# Basic kernel density plot of the metric for selected areas vs. all areas -splnr_plot_climKernelDensity( - soln = solution_df, - type = "Basic", - names = "solution_1" # Column indicating selected PUs (1=selected) -) - -# Fancy kernel density plot, perhaps with zones (if your solution has them) -# For this example, let's pretend 'solution_df' has a 'zone' column -# (this would come from a prioritizr zoned solution) -zoned_solution_df <- solution_df %>% - dplyr::mutate( - zone = sample(c("Zone A", "Zone B"), size = dplyr::n(), replace = TRUE) - ) - -# Example for Fancy (requires a list of solutions or specific structure) -# If you have multiple prioritizr solutions, you would put them in a list. -# For simplicity, we'll create a mock 'soln' list: -soln_list <- list( - Solution1 = zoned_solution_df, - Solution2 = zoned_solution_df %>% mutate(solution_1 = abs(solution_1 - 1)) # Invert selection for demo -) - -# plot_climKernelDensity handles both basic and fancy automatically -splnr_plot_climKernelDensity( - soln = soln_list, # Pass the list of solutions - names = c("metric", "metric"), - type = "Normal" # Explicitly request fancy - # zone_column = "zone" # If your solutions have zones -) -``` - -3. Plot Prioritization Solutions -Function: `splnr_plot_solution()` - -Visualizes the spatial output of a prioritizr problem, showing which planning units were selected for conservation. It supports both single-zone and multi-zone solutions. - -```{r} - -# Plot a single-zone solution -splnr_plot_solution( - soln = solution_df, - colorVals = c("grey", "darkgreen"), - legendLabels = c("Not Selected", "Selected"), - plotTitle = "Prioritization Solution (Single Zone)" -) - -# Plot a zoned solution (assuming 'zone' column exists) -# In a real scenario, this 'zone' column would be part of your prioritizr output. -# splnr_plot_solution( -# soln = zoned_solution_df, -# colorVals = c("red", "blue", "grey"), # Colors for each zone + not selected -# legendLabels = c("Zone A", "Zone B", "Not Selected"), -# plotTitle = "Prioritization Solution (Zoned)", -# zones = TRUE -# ) -``` - - -4. Plot Cost Overlay -Function: `splnr_plot_costOverlay()` - -Overlays cost data on top of a prioritization solution, helping to visualize the spatial distribution of costs relative to selected areas. - -```{r} -# Assuming 'solution_df' and adding a 'cost' column -solution_with_cost <- solution_df %>% - dplyr::mutate(cost = runif(dplyr::n(), 100, 1000)) - -splnr_plot_costOverlay( - soln = solution_with_cost, - costName = "cost", # Name of the cost column - # costName = "Acquisition Cost", - # colorVals = c("grey", "darkgreen"), - # legendLabels = c("Not Selected", "Selected"), - plotTitle = "Prioritization Solution with Cost Overlay" -) - -``` - -5. Plot Comparison -Function: `splnr_plot_comparison()` - -Compares two different prioritization solutions, highlighting areas that are uniquely selected by each solution, or selected by both. - -```{r} -# Assuming two solutions for comparison -soln1_df <- solution_df %>% - dplyr::mutate(solution_1 = sample(c(0, 1), dplyr::n(), replace = TRUE, prob = c(0.6, 0.4))) -soln2_df <- solution_df %>% - dplyr::mutate(solution_1 = sample(c(0, 1), dplyr::n(), replace = TRUE, prob = c(0.5, 0.5))) - -splnr_plot_comparison( - soln1 = soln1_df, - soln2 = soln2_df, -) - -``` - -6. Plot Selection Frequency -Function: `splnr_plot_selectionFreq()` - -Visualizes the frequency with which each planning unit is selected across multiple runs of a prioritization problem (e.g., from a sensitivity analysis or robust solution generation). - -```{r} -# # Create selection frequency data -# selection_freq_df <- solution_df %>% -# dplyr::mutate( -# selection_frequency = runif(dplyr::n(), 0, 1) # Frequency between 0 and 1 -# ) -# -# splnr_plot_selectionFreq( -# selFreq = selection_freq_df, -# plotTitle = "Selection Frequency of Planning Units", -# legendTitle = "Selection Frequency" -# ) -``` - -7. Plot Importance Score -Function: `splnr_plot_importanceScore()` - -Calculates and visualizes an "importance score" for each planning unit, which can represent its contribution to achieving targets or its irreplaceability. Useful for identifying key areas. - -```{r} -# -# splnr_plot_importanceScore( -# soln = solution_df, -# pDat = dat_species_bin, # Original biodiversity features -# method = "basic", # Or "complex" -# decimals = 2, -# plotTitle = "Planning Unit Importance Score" -# ) -``` - -8. Plot Correlation Matrix -Function: `splnr_plot_corrMat()` - -Generates a correlation matrix plot, useful for understanding relationships between different features or variables in your planning data. - -```{r} -# # Create a data matrix for correlation -# -# corr_data <- data.frame( -# Var1 = rnorm(100), -# Var2 = rnorm(100, mean = 0.5, sd = 1), -# Var3 = rnorm(100, mean = -0.2, sd = 0.5) -# ) -# # Add some correlation -# corr_data$Var2 <- corr_data$Var2 + 0.5 * corr_data$Var1 -# corr_data$Var3 <- corr_data$Var3 - 0.3 * corr_data$Var1 -# -# # Calculate correlation matrix -# corr_matrix <- cor(corr_data) -# -# splnr_plot_corrMat( -# matrix = corr_matrix, -# plotTitle = "Correlation Matrix of Variables" -# ) - -``` - -9. Generic Plotting Utility -Function: `splnr_plot()` - -A versatile plotting function that can be used to visualize any continuous or categorical data column within an sf dataframe, with options for color palettes and legend customization. Many other plotting functions in _spatialplanr_ internally use this function. - -```{r} -# Plotting the 'metric' column from 'dat_clim' using the generic plotter -splnr_plot( - df = dat_clim, - colNames = "metric", - plotTitle = "Generic Plot of Climate Metric", - legendTitle = "Metric Value", - paletteName = "viridis" # Use a viridis color palette -) - -``` - -# Example Workflow -The following example illustrates a typical workflow using _spatialplanr_ for climate-smart conservation planning. It assumes you have already prepared your planning units, biodiversity features, and cost layers. - -A typical workflow using _spatialplanr_ for climate-smart conservation planning might look like this: - -## Data Preparation: - -* Load your planning units (PUs). -* Load your biodiversity features (features). -* Load your cost layer (costs). -* Load your climate metric data (climate_data). -* (Optional) Use splnr_get_IUCNRedList() to refine species targets or splnr_get_gfw() to generate a cost layer. - -Choose Climate-Smart Approach: - -* Decide which climate-smart approach best suits your planning goals: - * `splnr_climate_priorityAreaApproach()` for prioritizing refugia for each feature. - * `splnr_climate_featureApproach()` for treating climate resilience as a standalone feature. - * `splnr_climate_percentileApproach()` for targeting specific climate metric ranges. -* Run the chosen function to obtain climate_features and climate_targets. -* Define and Solve Prioritization Problem (using _prioritizr_): - -Create a prioritizr problem using your PUs, climate_features, and climate_targets. -* Add objectives (e.g., `add_min_set_objective()`, `add_max_targets_objective()`). -* Add constraints (e.g., `add_budget_constraint()`, `add_contiguity_constraint()`, `add_locked_in_constraint()` for existing MPAs). -* Add solvers (e.g., `add_gurobi_solver()`, `add_cbc_solver()`). -* Solve the problem to get your solution. - -Visualize and Analyze Results (using _spatialplanr_ plotting functions): -* `splnr_plot_solution()` to visualize the selected planning units. -* `splnr_plot_costOverlay()` to see costs in selected areas. -* `splnr_plot_climKernelDensity()` to assess the climate characteristics of the solution. -* `splnr_plot_comparison()` to compare different scenarios or solutions. -* `splnr_plot_selectionFreq()` for robust solutions. -* `splnr_plot_importanceScore()` to identify key planning units. -* `splnr_plot_corrMat()` to understand feature relationships. - - -# Conclusion -_spatialplanr_ provides a powerful and flexible toolkit for integrating climate change considerations into spatial conservation prioritization. By offering multiple methodological approaches, streamlining data handling, and providing comprehensive visualization capabilities, it aims to empower conservation planners to create more resilient and effective protected area networks for the future. + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/README.md b/README.md index b6133b1a..f617833b 100644 --- a/README.md +++ b/README.md @@ -1,7 +1,7 @@ -# spatialplanr \“spatialplanrspatialplanr website @@ -21,8 +21,7 @@ Welcome to *spatialplanr*, an R package designed to streamline and enhance spatial conservation prioritization efforts by explicitly integrating climate change considerations. Building upon the powerful *prioritizr* package, *spatialplanr* provides a suite of tools for -conservation planners to develop more robust and climate-resilient -protected area networks. +conservation planners to develop robust protected area networks. ## Installation @@ -36,454 +35,524 @@ development version from [GitHub](https://github.com/) with: devtools::install_github("https://github.com/SpatialPlanning/spatialplanr") ``` -# Purpose and Goals - -The escalating impacts of climate change necessitate a paradigm shift in -how we approach conservation. Traditional conservation planning often -focuses on static biodiversity patterns, which may not adequately -account for the dynamic nature of species distributions and ecosystem -processes under a changing climate. *spatialplanr* aims to address this -gap by: - -**Facilitating Climate-Smart Planning**: Providing functions that -incorporate climate data directly into the planning process, allowing -for the identification of areas critical for both biodiversity and -resilience to future climate conditions. Offering Diverse Methodological -Approaches: Implementing multiple established climate-smart conservation -planning frameworks (e.g., Climate Priority Areas, Climate Features, -Climate Percentiles) to offer flexibility based on specific planning -goals and data availability. - -**Streamlining Workflow**: Offering end-to-end functionality, from data -preprocessing and integration to advanced visualization of results, -simplifying complex analytical tasks for users. - -**Enhancing Decision-Making**: Producing outputs that directly feed into -spatial prioritization software like prioritizr, enabling the generation -of optimal conservation solutions that balance biodiversity -representation with climate resilience. By using spatialplanr, -practitioners can move beyond reactive conservation and proactively -design protected area systems better equipped to safeguard biodiversity -in a rapidly changing world. - -# Core Climate-Smart Planning Approaches - -*spatialplanr* implements several key approaches for integrating climate -change into spatial prioritization, largely drawing inspiration from -frameworks like that presented in Buenafe et al. (2023) “A metric‐based -framework for climate‐smart conservation planning” (DOI: -10.1002/eap.2852). - -These approaches are designed to transform biodiversity features and -conservation targets based on climate metrics, allowing for a more -nuanced understanding of how climate change may impact conservation -priorities. The main approaches included in *spatialplanr* are: \* -**Climate Priority Area (CPA) Approach**: Identifies climate-smart areas -within the distribution of each conservation feature, creating new -components for climate-smart and non-climate-smart areas. \* **Climate -Feature Approach**: Treats climate-smart areas as a distinct -conservation feature, allowing for explicit conservation targets on -climate resilience. \* **Climate Percentile Approach**: Sets -conservation targets based on percentile ranges of climate metrics, -allowing for targeted protection of areas within specific climate -resilience thresholds. - -# Data Acquisition and Preprocessing Utilities - -*spatialplanr* also provides convenience functions for acquiring and -preparing data, which can be crucial for climate-smart planning. + -``` r -# Load spatialplanr -library(spatialplanr) -library(tidyverse) -#> ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ── -#> ✔ dplyr 1.1.4 ✔ readr 2.1.5 -#> ✔ forcats 1.0.0 ✔ stringr 1.5.1 -#> ✔ ggplot2 3.5.2 ✔ tibble 3.3.0 -#> ✔ lubridate 1.9.4 ✔ tidyr 1.3.1 -#> ✔ purrr 1.0.4 -#> ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ── -#> ✖ dplyr::filter() masks stats::filter() -#> ✖ dplyr::lag() masks stats::lag() -#> ℹ Use the conflicted package () to force all conflicts to become errors -``` + -1. Get IUCN Red List Data Function: `splnr_get_IUCNRedList()` + -This function interfaces with the IUCN Red List API to retrieve -conservation status information for a list of species. This data can be -valuable for assigning species-specific targets (e.g., higher targets -for more threatened species) or filtering species based on their -conservation status. + -Note: Requires an IUCN Red List API token. + -``` r -# # Example: Fetch IUCN data for a few marine species -# # Ensure your IUCN Red List API token is set: -# # Sys.setenv(IUCN_REDLIST_KEY = "YOUR_API_KEY") # Replace with your actual key -# -# # Example species list -# my_species <- c("Orcinus orca", "Chelonia mydas", "Thunnus thynnus") -# -# # Create a dataframe matching the expected input format -# species_df <- data.frame( -# scientific_name = my_species -# ) -# -# # Get IUCN data -# iucn_data <- splnr_get_IUCNRedList(df = species_df, species_col = "scientific_name") -# print(iucn_data) -``` + -2. Get Global Fishing Watch (GFW) Data Function: `splnr_get_gfw()` + -This function facilitates the retrieval of fishing activity data (e.g., -apparent fishing hours) from Global Fishing Watch (GFW). GFW data can be -used to inform cost layers (e.g., higher fishing effort areas might have -higher opportunity costs for conservation) or as a proxy for human -impact in planning units. + -Note: Requires a GFW API token. + -``` r -# Example: Get yearly fishing hours for Australia EEZ - -gfw_data_aus <- splnr_get_gfw( - region = 'Australia', - start_date = "2021-01-01", - end_date = "2021-12-31", - temp_res = "YEARLY", - spat_res = "LOW", - region_source = "EEZ", - cCRS = "EPSG:4326", - compress = TRUE # Returns polygons aggregated by fishing hours -) -print(head(gfw_data_aus)) -#> Simple feature collection with 6 features and 2 fields -#> Geometry type: POLYGON -#> Dimension: XY -#> Bounding box: xmin: 104.05 ymin: -8.85 xmax: 104.75 ymax: -8.65 -#> Geodetic CRS: WGS 84 -#> # A tibble: 6 × 3 -#> geometry ApparentFishingHrs GFWregionID -#> -#> 1 ((104.45 -8.75, 104.45 -8.65, 104.55 -8.65, 10… 1.04 8309 -#> 2 ((104.55 -8.75, 104.55 -8.65, 104.65 -8.65, 10… 6.45 8309 -#> 3 ((104.05 -8.85, 104.05 -8.75, 104.15 -8.75, 10… 2.89 8309 -#> 4 ((104.25 -8.85, 104.25 -8.75, 104.35 -8.75, 10… 7.34 8309 -#> 5 ((104.45 -8.85, 104.45 -8.75, 104.55 -8.75, 10… 2.02 8309 -#> 6 ((104.65 -8.85, 104.65 -8.75, 104.75 -8.75, 10… 6.32 8309 -``` + -## Visualization Tools + -*spatialplanr* offers a rich set of plotting functions to visualize -input data, climate metrics, and most importantly, the outputs of your -spatial prioritization analyses. These functions are built on ggplot2 -and sf for high-quality spatial visualizations. + -1. Plot Climate Data Function: `splnr_plot_climData()` + -Visualizes the spatial distribution of your climate metric, allowing you -to quickly inspect patterns in climate velocity, temperature anomaly, or -other relevant climate variables. + -``` r -# Assuming 'dat_clim' from previous examples is available -# Plot the 'metric' column from dat_clim -splnr_plot_climData( - df = dat_clim, - colInterest = "metric", - plotTitle = "Example Climate Metric Distribution", - legendTitle = "Metric Value" -) -``` + - + -2. Plot Climate Kernel Density Functions: - `splnr_plot_climKernelDensity_Basic()`, - `splnr_plot_climKernelDensity_Fancy()`, - `splnr_plot_climKernelDensity()` + -These functions help visualize the distribution of climate metric values -within selected planning units (e.g., a proposed protected area network) -compared to the overall distribution. This helps assess if climate-smart -areas are being adequately captured. + -`_Basic()`: Simple kernel density plot. `_Fancy()`: More customizable -kernel density plot, allowing multiple solutions and specific zones. -`_climKernelDensity()`: A wrapper function that selects between basic -and fancy plots based on input type. + -``` r -solution_df <- dat_clim %>% - dplyr::mutate( - solution_1 = sample(c(0, 1), size = dplyr::n(), replace = TRUE, prob = c(0.7, 0.3)), - metric_category = cut(metric, breaks = 3, labels = c("Low", "Medium", "High")) - ) - -# Basic kernel density plot of the metric for selected areas vs. all areas -splnr_plot_climKernelDensity( - soln = solution_df, - type = "Basic", - names = "solution_1" # Column indicating selected PUs (1=selected) -) - -#> Picking joint bandwidth of 0.0885 -#> Picking joint bandwidth of 0.077 + -``` + - + -``` r + -# Fancy kernel density plot, perhaps with zones (if your solution has them) -# For this example, let's pretend 'solution_df' has a 'zone' column -# (this would come from a prioritizr zoned solution) -zoned_solution_df <- solution_df %>% - dplyr::mutate( - zone = sample(c("Zone A", "Zone B"), size = dplyr::n(), replace = TRUE) - ) - -# Example for Fancy (requires a list of solutions or specific structure) -# If you have multiple prioritizr solutions, you would put them in a list. -# For simplicity, we'll create a mock 'soln' list: -soln_list <- list( - Solution1 = zoned_solution_df, - Solution2 = zoned_solution_df %>% mutate(solution_1 = abs(solution_1 - 1)) # Invert selection for demo -) - -# plot_climKernelDensity handles both basic and fancy automatically -splnr_plot_climKernelDensity( - soln = soln_list, # Pass the list of solutions - names = c("metric", "metric"), - type = "Normal" # Explicitly request fancy - # zone_column = "zone" # If your solutions have zones -) -#> Picking joint bandwidth of 0.071 -#> Picking joint bandwidth of 0.071 -``` + - + -3. Plot Prioritization Solutions Function: `splnr_plot_solution()` + -Visualizes the spatial output of a prioritizr problem, showing which -planning units were selected for conservation. It supports both -single-zone and multi-zone solutions. + -``` r + -# Plot a single-zone solution -splnr_plot_solution( - soln = solution_df, - colorVals = c("grey", "darkgreen"), - legendLabels = c("Not Selected", "Selected"), - plotTitle = "Prioritization Solution (Single Zone)" -) -``` + - + -``` r + -# Plot a zoned solution (assuming 'zone' column exists) -# In a real scenario, this 'zone' column would be part of your prioritizr output. -# splnr_plot_solution( -# soln = zoned_solution_df, -# colorVals = c("red", "blue", "grey"), # Colors for each zone + not selected -# legendLabels = c("Zone A", "Zone B", "Not Selected"), -# plotTitle = "Prioritization Solution (Zoned)", -# zones = TRUE -# ) -``` + -4. Plot Cost Overlay Function: `splnr_plot_costOverlay()` + -Overlays cost data on top of a prioritization solution, helping to -visualize the spatial distribution of costs relative to selected areas. + -``` r -# Assuming 'solution_df' and adding a 'cost' column -solution_with_cost <- solution_df %>% - dplyr::mutate(cost = runif(dplyr::n(), 100, 1000)) - -splnr_plot_costOverlay( - soln = solution_with_cost, - costName = "cost", # Name of the cost column - # costName = "Acquisition Cost", - # colorVals = c("grey", "darkgreen"), - # legendLabels = c("Not Selected", "Selected"), - plotTitle = "Prioritization Solution with Cost Overlay" -) -``` + - + -5. Plot Comparison Function: `splnr_plot_comparison()` + -Compares two different prioritization solutions, highlighting areas that -are uniquely selected by each solution, or selected by both. + -``` r -# Assuming two solutions for comparison -soln1_df <- solution_df %>% - dplyr::mutate(solution_1 = sample(c(0, 1), dplyr::n(), replace = TRUE, prob = c(0.6, 0.4))) -soln2_df <- solution_df %>% - dplyr::mutate(solution_1 = sample(c(0, 1), dplyr::n(), replace = TRUE, prob = c(0.5, 0.5))) - -splnr_plot_comparison( - soln1 = soln1_df, - soln2 = soln2_df, -) -``` + - + -6. Plot Selection Frequency Function: `splnr_plot_selectionFreq()` + -Visualizes the frequency with which each planning unit is selected -across multiple runs of a prioritization problem (e.g., from a -sensitivity analysis or robust solution generation). + -``` r -# # Create selection frequency data -# selection_freq_df <- solution_df %>% -# dplyr::mutate( -# selection_frequency = runif(dplyr::n(), 0, 1) # Frequency between 0 and 1 -# ) -# -# splnr_plot_selectionFreq( -# selFreq = selection_freq_df, -# plotTitle = "Selection Frequency of Planning Units", -# legendTitle = "Selection Frequency" -# ) -``` + -7. Plot Importance Score Function: `splnr_plot_importanceScore()` + -Calculates and visualizes an “importance score” for each planning unit, -which can represent its contribution to achieving targets or its -irreplaceability. Useful for identifying key areas. + -``` r -# -# splnr_plot_importanceScore( -# soln = solution_df, -# pDat = dat_species_bin, # Original biodiversity features -# method = "basic", # Or "complex" -# decimals = 2, -# plotTitle = "Planning Unit Importance Score" -# ) -``` + -8. Plot Correlation Matrix Function: `splnr_plot_corrMat()` + -Generates a correlation matrix plot, useful for understanding -relationships between different features or variables in your planning -data. + -``` r -# # Create a data matrix for correlation -# -# corr_data <- data.frame( -# Var1 = rnorm(100), -# Var2 = rnorm(100, mean = 0.5, sd = 1), -# Var3 = rnorm(100, mean = -0.2, sd = 0.5) -# ) -# # Add some correlation -# corr_data$Var2 <- corr_data$Var2 + 0.5 * corr_data$Var1 -# corr_data$Var3 <- corr_data$Var3 - 0.3 * corr_data$Var1 -# -# # Calculate correlation matrix -# corr_matrix <- cor(corr_data) -# -# splnr_plot_corrMat( -# matrix = corr_matrix, -# plotTitle = "Correlation Matrix of Variables" -# ) -``` + -9. Generic Plotting Utility Function: `splnr_plot()` + -A versatile plotting function that can be used to visualize any -continuous or categorical data column within an sf dataframe, with -options for color palettes and legend customization. Many other plotting -functions in *spatialplanr* internally use this function. + -``` r -# Plotting the 'metric' column from 'dat_clim' using the generic plotter -splnr_plot( - df = dat_clim, - colNames = "metric", - plotTitle = "Generic Plot of Climate Metric", - legendTitle = "Metric Value", - paletteName = "viridis" # Use a viridis color palette -) -#> Coordinate system already present. Adding new coordinate system, which will -#> replace the existing one. -``` + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - -# Example Workflow - -The following example illustrates a typical workflow using -*spatialplanr* for climate-smart conservation planning. It assumes you -have already prepared your planning units, biodiversity features, and -cost layers. - -A typical workflow using *spatialplanr* for climate-smart conservation -planning might look like this: - -## Data Preparation: - -- Load your planning units (PUs). -- Load your biodiversity features (features). -- Load your cost layer (costs). -- Load your climate metric data (climate_data). -- (Optional) Use splnr_get_IUCNRedList() to refine species targets or - splnr_get_gfw() to generate a cost layer. - -Choose Climate-Smart Approach: - -- Decide which climate-smart approach best suits your planning goals: - - `splnr_climate_priorityAreaApproach()` for prioritizing refugia for - each feature. - - `splnr_climate_featureApproach()` for treating climate resilience as - a standalone feature. - - `splnr_climate_percentileApproach()` for targeting specific climate - metric ranges. -- Run the chosen function to obtain climate_features and - climate_targets. -- Define and Solve Prioritization Problem (using *prioritizr*): - -Create a prioritizr problem using your PUs, climate_features, and -climate_targets. \* Add objectives (e.g., `add_min_set_objective()`, -`add_max_targets_objective()`). \* Add constraints (e.g., -`add_budget_constraint()`, `add_contiguity_constraint()`, -`add_locked_in_constraint()` for existing MPAs). \* Add solvers (e.g., -`add_gurobi_solver()`, `add_cbc_solver()`). \* Solve the problem to get -your solution. - -Visualize and Analyze Results (using *spatialplanr* plotting functions): -\* `splnr_plot_solution()` to visualize the selected planning units. \* -`splnr_plot_costOverlay()` to see costs in selected areas. \* -`splnr_plot_climKernelDensity()` to assess the climate characteristics -of the solution. \* `splnr_plot_comparison()` to compare different -scenarios or solutions. \* `splnr_plot_selectionFreq()` for robust -solutions. \* `splnr_plot_importanceScore()` to identify key planning -units. \* `splnr_plot_corrMat()` to understand feature relationships. - -# Conclusion - -*spatialplanr* provides a powerful and flexible toolkit for integrating -climate change considerations into spatial conservation prioritization. -By offering multiple methodological approaches, streamlining data -handling, and providing comprehensive visualization capabilities, it -aims to empower conservation planners to create more resilient and -effective protected area networks for the future. + diff --git a/docs/404.html b/docs/404.html index 4ca3ae9c..16f564a2 100644 --- a/docs/404.html +++ b/docs/404.html @@ -26,7 +26,7 @@ spatialplanr - 0.6.9 + 0.7.0 "; + if (ClipboardJS.isSupported()) { + $(document).ready(function () { + var copyButton = ""; - $("div.sourceCode").addClass("hasCopyButton"); + $("div.sourceCode").addClass("hasCopyButton"); - // Insert copy buttons: - $(copyButton).prependTo(".hasCopyButton"); + // Insert copy buttons: + $(copyButton).prependTo(".hasCopyButton"); - // Initialize tooltips: - $('.btn-copy-ex').tooltip({container: 'body'}); + // Initialize tooltips: + $('.btn-copy-ex').tooltip({ container: 'body' }); - // Initialize clipboard: - var clipboard = new ClipboardJS('[data-clipboard-copy]', { - text: function(trigger) { - return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); - } - }); + // Initialize clipboard: + var clipboard = new ClipboardJS('[data-clipboard-copy]', { + text: function (trigger) { + return trigger.parentNode.textContent.replace(/\n#>[^\n]*/g, ""); + } + }); - clipboard.on('success', function(e) { - changeTooltipMessage(e.trigger, 'Copied!'); - e.clearSelection(); - }); + clipboard.on('success', function (e) { + changeTooltipMessage(e.trigger, 'Copied!'); + e.clearSelection(); + }); - clipboard.on('error', function(e) { - changeTooltipMessage(e.trigger,'Press Ctrl+C or Command+C to copy'); - }); + clipboard.on('error', function (e) { + changeTooltipMessage(e.trigger, 'Press Ctrl+C or Command+C to copy'); + }); - }); - } + }); + } /* Search marking --------------------------*/ var url = new URL(window.location.href); @@ -80,80 +80,80 @@ }); } - /* Search --------------------------*/ - /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */ + /* Search --------------------------*/ + /* Adapted from https://github.com/rstudio/bookdown/blob/2d692ba4b61f1e466c92e78fd712b0ab08c11d31/inst/resources/bs4_book/bs4_book.js#L25 */ // Initialise search index on focus - var fuse; - $("#search-input").focus(async function(e) { - if (fuse) { - return; - } - - $(e.target).addClass("loading"); - var response = await fetch($("#search-input").data("search-index")); - var data = await response.json(); + var fuse; + $("#search-input").focus(async function (e) { + if (fuse) { + return; + } + + $(e.target).addClass("loading"); + var response = await fetch($("#search-input").data("search-index")); + var data = await response.json(); + + var options = { + keys: ["what", "text", "code"], + ignoreLocation: true, + threshold: 0.1, + includeMatches: true, + includeScore: true, + }; + fuse = new Fuse(data, options); + + $(e.target).removeClass("loading"); + }); + // Use algolia autocomplete var options = { - keys: ["what", "text", "code"], - ignoreLocation: true, - threshold: 0.1, - includeMatches: true, - includeScore: true, + autoselect: true, + debug: true, + hint: false, + minLength: 2, }; - fuse = new Fuse(data, options); - - $(e.target).removeClass("loading"); - }); - - // Use algolia autocomplete - var options = { - autoselect: true, - debug: true, - hint: false, - minLength: 2, - }; - var q; -async function searchFuse(query, callback) { - await fuse; - - var items; - if (!fuse) { - items = []; - } else { - q = query; - var results = fuse.search(query, { limit: 20 }); - items = results - .filter((x) => x.score <= 0.75) - .map((x) => x.item); - if (items.length === 0) { - items = [{dir:"Sorry 😿",previous_headings:"",title:"No results found.",what:"No results found.",path:window.location.href}]; + var q; + async function searchFuse(query, callback) { + await fuse; + + var items; + if (!fuse) { + items = []; + } else { + q = query; + var results = fuse.search(query, { limit: 20 }); + items = results + .filter((x) => x.score <= 0.75) + .map((x) => x.item); + if (items.length === 0) { + items = [{ dir: "Sorry 😿", previous_headings: "", title: "No results found.", what: "No results found.", path: window.location.href }]; + } + } + callback(items); } - } - callback(items); -} - $("#search-input").autocomplete(options, [ - { - name: "content", - source: searchFuse, - templates: { - suggestion: (s) => { - if (s.title == s.what) { - return `${s.dir} >
${s.title}
`; - } else if (s.previous_headings == "") { - return `${s.dir} >
${s.title}
> ${s.what}`; - } else { - return `${s.dir} >
${s.title}
> ${s.previous_headings} > ${s.what}`; - } + $("#search-input").autocomplete(options, [ + { + name: "content", + source: searchFuse, + templates: { + suggestion: (s) => { + if (s.title == s.what) { + return `${s.dir} >
${s.title}
`; + } else if (s.previous_headings == "") { + return `${s.dir} >
${s.title}
> ${s.what}`; + } else { + return `${s.dir} >
${s.title}
> ${s.previous_headings} > ${s.what}`; + } + }, }, }, - }, - ]).on('autocomplete:selected', function(event, s) { - window.location.href = s.path + "?q=" + q + "#" + s.id; - }); + ]).on('autocomplete:selected', function (event, s) { + window.location.href = s.path + "?q=" + q + "#" + s.id; + }); }); })(window.jQuery || window.$) -document.addEventListener('keydown', function(event) { +document.addEventListener('keydown', function (event) { // Check if the pressed key is '/' if (event.key === '/') { event.preventDefault(); // Prevent any default action associated with the '/' key diff --git a/docs/pkgdown.yml b/docs/pkgdown.yml index 678677ec..73a166b7 100644 --- a/docs/pkgdown.yml +++ b/docs/pkgdown.yml @@ -1,12 +1,12 @@ -pandoc: '3.4' -pkgdown: 2.1.3 +pandoc: 3.8.2.1 +pkgdown: 2.2.0 pkgdown_sha: ~ articles: ClimateSmart: ClimateSmart.html GlobalFishingWatch: GlobalFishingWatch.html MultipleUse: MultipleUse.html spatialplanr: spatialplanr.html -last_built: 2025-06-18T02:23Z +last_built: 2025-11-17T19:08Z urls: reference: https://mathmarecol.github.io/spatialplanr/reference article: https://mathmarecol.github.io/spatialplanr/articles diff --git a/docs/reference/CoralSeaVelocity.html b/docs/reference/CoralSeaVelocity.html index 14c65867..d8561437 100644 --- a/docs/reference/CoralSeaVelocity.html +++ b/docs/reference/CoralSeaVelocity.html @@ -7,7 +7,7 @@ spatialplanr - 0.6.9 + 0.7.0