diff --git a/DESCRIPTION b/DESCRIPTION index b1cf2426..e194c9a2 100644 --- a/DESCRIPTION +++ b/DESCRIPTION @@ -1,6 +1,6 @@ Package: spatialplanr Title: Help files for prioritzr Spatial Planning projects -Version: 0.7.5 +Version: 0.7.6 Authors@R: c( person( given = "Jason D.", @@ -43,9 +43,8 @@ Depends: Imports: assertthat, dplyr, - forcats, ggnewscale, - ggplot2, + ggplot2 (>= 4.0.0), ggridges, lifecycle, magrittr, @@ -73,4 +72,4 @@ Remotes: github::prioritizr/wdpar, github::ropensci/rnaturalearthhires Config/testthat/edition: 3 -Config/roxygen2/version: 8.0.0 +Config/roxygen2/version: 8.1.0 diff --git a/NAMESPACE b/NAMESPACE index 5b6295ae..40de3fa7 100644 --- a/NAMESPACE +++ b/NAMESPACE @@ -40,143 +40,175 @@ export(splnr_scale_01) export(splnr_targets_byCategory) export(splnr_targets_byIUCN) export(splnr_targets_byInverseArea) -importFrom(assertthat,assert_that) -importFrom(assertthat,is.flag) -importFrom(assertthat,is.string) -importFrom(dplyr,across) -importFrom(dplyr,all_of) -importFrom(dplyr,any_of) -importFrom(dplyr,arrange) -importFrom(dplyr,as_tibble) -importFrom(dplyr,bind_cols) -importFrom(dplyr,bind_rows) -importFrom(dplyr,case_when) -importFrom(dplyr,coalesce) -importFrom(dplyr,everything) -importFrom(dplyr,filter) -importFrom(dplyr,group_by) -importFrom(dplyr,if_else) -importFrom(dplyr,left_join) -importFrom(dplyr,mutate) -importFrom(dplyr,pull) -importFrom(dplyr,rename) -importFrom(dplyr,rename_at) -importFrom(dplyr,rename_with) -importFrom(dplyr,row_number) -importFrom(dplyr,rowwise) -importFrom(dplyr,select) -importFrom(dplyr,starts_with) -importFrom(dplyr,summarise) -importFrom(dplyr,summarize) -importFrom(dplyr,tibble) -importFrom(dplyr,ungroup) -importFrom(ggnewscale,new_scale_colour) -importFrom(ggnewscale,new_scale_fill) -importFrom(ggplot2,aes) -importFrom(ggplot2,annotate) -importFrom(ggplot2,coord_polar) -importFrom(ggplot2,coord_sf) -importFrom(ggplot2,element_blank) -importFrom(ggplot2,element_line) -importFrom(ggplot2,element_rect) -importFrom(ggplot2,element_text) -importFrom(ggplot2,geom_abline) -importFrom(ggplot2,geom_bar) -importFrom(ggplot2,geom_segment) -importFrom(ggplot2,geom_sf) -importFrom(ggplot2,geom_text) -importFrom(ggplot2,ggplot) -importFrom(ggplot2,guide_axis) -importFrom(ggplot2,guide_colourbar) -importFrom(ggplot2,guide_legend) -importFrom(ggplot2,guides) -importFrom(ggplot2,labs) -importFrom(ggplot2,scale_fill_brewer) -importFrom(ggplot2,scale_fill_distiller) -importFrom(ggplot2,scale_fill_gradient) -importFrom(ggplot2,scale_fill_gradient2) -importFrom(ggplot2,scale_fill_manual) -importFrom(ggplot2,scale_fill_viridis_c) -importFrom(ggplot2,scale_linetype_manual) -importFrom(ggplot2,scale_x_continuous) -importFrom(ggplot2,scale_x_discrete) -importFrom(ggplot2,scale_y_continuous) -importFrom(ggplot2,scale_y_discrete) -importFrom(ggplot2,theme) -importFrom(ggplot2,theme_bw) -importFrom(ggplot2,theme_minimal) -importFrom(ggplot2,unit) -importFrom(ggplot2,ylim) +importFrom(assertthat, + assert_that, + is.flag, + is.string +) +importFrom(dplyr, + across, + all_of, + any_of, + arrange, + as_tibble, + bind_cols, + bind_rows, + case_when, + coalesce, + everything, + filter, + group_by, + if_else, + left_join, + mutate, + pull, + rename, + rename_at, + rename_with, + row_number, + rowwise, + select, + starts_with, + summarise, + summarize, + tibble, + ungroup +) +importFrom(ggnewscale, + new_scale_colour, + new_scale_fill +) +importFrom(ggplot2, + aes, + annotate, + coord_polar, + coord_sf, + element_blank, + element_line, + element_rect, + element_text, + geom_abline, + geom_bar, + geom_segment, + geom_sf, + geom_text, + ggplot, + guide_axis, + guide_colourbar, + guide_legend, + guides, + labs, + scale_fill_brewer, + scale_fill_distiller, + scale_fill_gradient, + scale_fill_gradient2, + scale_fill_manual, + scale_fill_viridis_c, + scale_linetype_manual, + scale_x_continuous, + scale_x_discrete, + scale_y_continuous, + scale_y_discrete, + theme, + theme_bw, + theme_minimal, + unit, + ylim +) importFrom(grid,unit) -importFrom(lifecycle,deprecate_warn) -importFrom(lifecycle,deprecated) +importFrom(lifecycle, + deprecate_warn, + deprecated +) importFrom(magrittr,"%>%") -importFrom(prioritizr,add_binary_decisions) -importFrom(prioritizr,add_cuts_portfolio) -importFrom(prioritizr,add_default_solver) -importFrom(prioritizr,add_min_set_objective) -importFrom(prioritizr,add_relative_targets) -importFrom(prioritizr,eval_feature_representation_summary) -importFrom(prioritizr,eval_ferrier_importance) -importFrom(prioritizr,eval_rare_richness_importance) -importFrom(prioritizr,eval_replacement_importance) -importFrom(prioritizr,problem) -importFrom(prioritizr,solve.ConservationProblem) -importFrom(prioritizr,zones) -importFrom(purrr,map) -importFrom(purrr,map_dbl) -importFrom(purrr,map_df) -importFrom(purrr,map_lgl) -importFrom(purrr,map_vec) +importFrom(prioritizr, + add_binary_decisions, + add_cuts_portfolio, + add_default_solver, + add_min_set_objective, + add_relative_targets, + eval_feature_representation_summary, + eval_ferrier_importance, + eval_rare_richness_importance, + eval_replacement_importance, + problem, + solve.ConservationProblem, + zones +) +importFrom(purrr, + map, + map_dbl, + map_df, + map_lgl, + map_vec +) importFrom(rappdirs,user_data_dir) -importFrom(rlang,":=") -importFrom(rlang,.data) -importFrom(rlang,sym) -importFrom(rnaturalearth,ne_coastline) -importFrom(rnaturalearth,ne_download) +importFrom(rlang, + ":=", + .data, + sym +) +importFrom(rnaturalearth, + ne_coastline, + ne_download +) importFrom(scales,squish) -importFrom(sf,st_area) -importFrom(sf,st_as_sf) -importFrom(sf,st_bbox) -importFrom(sf,st_centroid) -importFrom(sf,st_coordinates) -importFrom(sf,st_crs) -importFrom(sf,st_distance) -importFrom(sf,st_drop_geometry) -importFrom(sf,st_geometry) -importFrom(sf,st_nearest_feature) -importFrom(sf,st_polygon) -importFrom(sf,st_set_crs) -importFrom(sf,st_set_geometry) -importFrom(sf,st_sf) -importFrom(sf,st_sfc) -importFrom(sf,st_transform) -importFrom(sf,st_union) +importFrom(sf, + st_area, + st_as_sf, + st_bbox, + st_centroid, + st_coordinates, + st_crs, + st_distance, + st_drop_geometry, + st_geometry, + st_nearest_feature, + st_polygon, + st_set_crs, + st_set_geometry, + st_sf, + st_sfc, + st_transform, + st_union +) importFrom(spatialgridr,get_data_in_grid) -importFrom(stats,na.omit) -importFrom(stats,quantile) -importFrom(stats,reorder) -importFrom(stats,setNames) -importFrom(stringr,str_c) -importFrom(stringr,str_pad) -importFrom(stringr,str_remove_all) -importFrom(stringr,str_replace_all) -importFrom(stringr,str_subset) -importFrom(tibble,as_tibble) -importFrom(tibble,deframe) -importFrom(tibble,enframe) -importFrom(tibble,rowid_to_column) -importFrom(tibble,tibble) -importFrom(tibble,tribble) -importFrom(tidyr,pivot_longer) -importFrom(tidyr,pivot_wider) -importFrom(tidyr,replace_na) -importFrom(tidyselect,all_of) -importFrom(tidyselect,any_of) -importFrom(tidyselect,everything) -importFrom(tidyselect,starts_with) -importFrom(tidyselect,where) -importFrom(units,drop_units) -importFrom(units,set_units) +importFrom(stats, + na.omit, + quantile, + reorder, + setNames +) +importFrom(stringr, + str_c, + str_pad, + str_remove_all, + str_replace_all, + str_subset +) +importFrom(tibble, + as_tibble, + deframe, + enframe, + rowid_to_column, + tibble, + tribble +) +importFrom(tidyr, + pivot_longer, + pivot_wider, + replace_na +) +importFrom(tidyselect, + all_of, + any_of, + everything, + starts_with, + where +) +importFrom(units, + drop_units, + set_units +) importFrom(vctrs,vec_c) importFrom(withr,with_options) diff --git a/R/splnr_featureRep.R b/R/splnr_featureRep.R index 36b668a7..4d8793f4 100644 --- a/R/splnr_featureRep.R +++ b/R/splnr_featureRep.R @@ -648,7 +648,7 @@ splnr_plot_featureRep <- function(df, legend.title = ggplot2::element_blank(), legend.position = "top", legend.direction = "horizontal", - legend.background = ggplot2::element_rect(fill = "NA"), + legend.background = ggplot2::element_rect(fill = "transparent", colour = NA), ... ) diff --git a/R/splnr_plot.R b/R/splnr_plot.R index 7ad283f0..9a76e372 100644 --- a/R/splnr_plot.R +++ b/R/splnr_plot.R @@ -266,9 +266,15 @@ splnr_plot <- function(df, ggplot2::scale_fill_viridis_c(name = legendTitle, aesthetics = c("colour", "fill")) + # Configure guides to show color bar for fill and hide color legend for outline. ggplot2::guides( - fill = ggplot2::guide_colourbar(order = 1), + fill = ggplot2::guide_colourbar( + order = 1, + title.position = "right", + title.hjust = 0.5, + title.theme = ggplot2::element_text(angle = -90) + ), colour = "none" ) + } 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. diff --git a/R/splnr_plotting.R b/R/splnr_plotting.R index 481c7ddd..4a889b92 100644 --- a/R/splnr_plotting.R +++ b/R/splnr_plotting.R @@ -227,7 +227,8 @@ splnr_plot <- function(df, barwidth = ggplot2::unit(2, "lines"), barheight = ggplot2::unit(10, "lines"), title.position = "right", - title.theme = ggplot2::element_text(angle = 270, vjust = 0.5) + title.hjust = 0.5, + title.theme = ggplot2::element_text(angle = -90) )) return(gg) @@ -275,7 +276,8 @@ splnr_plot <- function(df, barwidth = ggplot2::unit(2, "lines"), barheight = ggplot2::unit(10, "lines"), title.position = "right", - title.theme = ggplot2::element_text(angle = 270, vjust = 0.5) + title.hjust = 0.5, + title.theme = ggplot2::element_text(angle = -90) ), colour = "none" ) @@ -673,7 +675,8 @@ splnr_plot_costOverlay <- function(soln, barwidth = ggplot2::unit(2, "lines"), barheight = ggplot2::unit(10, "lines"), title.position = "right", - title.theme = ggplot2::element_text(angle = 270, vjust = 0.5) + title.hjust = 0.5, + title.theme = ggplot2::element_text(angle = -90) ) ) + # Set coordinate limits based on the bounding box of the cost data. @@ -1172,7 +1175,8 @@ splnr_plot_importanceScore <- function(soln, barwidth = ggplot2::unit(2, "lines"), barheight = ggplot2::unit(10, "lines"), title.position = "right", - title.theme = ggplot2::element_text(angle = 270, vjust = 0.5) + title.hjust = 0.5, + title.theme = ggplot2::element_text(angle = -90) ) ) + # Set coordinate limits based on the bounding box of the scored solution. @@ -1339,7 +1343,8 @@ splnr_plot_corrMat <- function(x, colourGradient = c("#BB4444", "#FFFFFF", "#447 barwidth = ggplot2::unit(2, "lines"), barheight = ggplot2::unit(10, "lines"), title.position = "right", - title.theme = ggplot2::element_text(angle = 270, vjust = 0.5) + title.hjust = 0.5, + title.theme = ggplot2::element_text(angle = -90) ) ) + # Rotate x-axis labels for better readability. diff --git a/R/splnr_plotting_climate.R b/R/splnr_plotting_climate.R index e26aee59..4734f53e 100644 --- a/R/splnr_plotting_climate.R +++ b/R/splnr_plotting_climate.R @@ -103,7 +103,14 @@ splnr_plot_climData <- function(df, # Apply a viridis continuous color scale for fill. ggplot2::scale_fill_viridis_c( name = legendTitle, # Set legend title. - option = colorMap # Apply specified color map. + option = colorMap, # Apply specified color map. + guide = ggplot2::guide_colorbar( + barheight = ggplot2::unit(10, "lines"), + barwidth = ggplot2::unit(2, "lines"), + title.position = "right", + title.hjust = 0.5, + title.theme = ggplot2::element_text(angle = -90) + ) ) + # Set coordinate limits based on the bounding box of the dataframe. ggplot2::coord_sf(xlim = sf::st_bbox(df)$xlim, ylim = sf::st_bbox(df)$ylim) + @@ -213,7 +220,7 @@ splnr_plot_climKernelDensity_Basic <- function(soln, base_size = 14) { axis.line = ggplot2::element_line(colour = "black", linewidth = 1), axis.text.y = ggplot2::element_blank(), # Hide y-axis text. axis.text.x = ggplot2::element_text(colour = "black"), - legend.title = ggplot2::element_text(color = "black", angle = 90, hjust = 0.5), # Rotate legend title. + legend.title = ggplot2::element_text(color = "black"), legend.position = "bottom", legend.text = ggplot2::element_text(colour = "black") ) + @@ -384,7 +391,10 @@ splnr_plot_climKernelDensity_Fancy <- function(soln, option = colorMap, guide = ggplot2::guide_colorbar( barheight = ggplot2::unit(10, "lines"), - barwidth = ggplot2::unit(2, "lines") + barwidth = ggplot2::unit(2, "lines"), + title.position = "right", + title.hjust = 0.5, + title.theme = ggplot2::element_text(angle = -90) ) ) + # Grey dotted ridge for unselected planning units. @@ -445,9 +455,7 @@ splnr_plot_climKernelDensity_Fancy <- function(soln, axis.text = ggplot2::element_text(color = "black"), axis.title.y = ggplot2::element_blank(), axis.text.y = ggplot2::element_blank(), - legend.text = ggplot2::element_text(color = "black"), - legend.title = ggplot2::element_text(color = "black"), - legend.title.position = "right" + legend.text = ggplot2::element_text(color = "black") ) return(ggRidge) diff --git a/docs/404.html b/docs/404.html index 406e4595..bb478c80 100644 --- a/docs/404.html +++ b/docs/404.html @@ -26,7 +26,7 @@ spatialplanr - 0.7.2 + 0.7.6
(ggSoln <- splnr_plot_solution(dat_solnClim) +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
However, we are also interested how climate-smart the selected planning units in the solution actually are. For this, we can use a kernel density plot.
(ggClimDens <- splnr_plot_climKernelDensity(
- soln = list(dat_solnClim),
- # names = c("Input 1"),
+ soln = dat_solnClim,
type = "Normal",
legendTitle = "Climate velocity (add unit)",
xAxisLab = "Climate velocity"
@@ -337,9 +339,9 @@ Percentile ApproachPercentile_Approach <- splnr_climate_percentileApproach(
features = datEx_species_bin,
- metric = metric,
- targets = targets,
- direction = -1,
+ metric = metric,
+ targets = targets,
+ direction = -1,
percentile = 35
)
@@ -375,24 +377,24 @@ Percentile Approachprioritizr::add_default_solver(verbose = FALSE)
dat_solnClimPercentile <- prioritizr::solve.ConservationProblem(p2,
- force = TRUE
+ force = TRUE
)
We can look at the resulting plan using
splnr_plot_solution().
(ggSoln <- splnr_plot_solution(dat_solnClimPercentile) +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
However, we are also interested how climate-smart the selected planning units in the solution actually are. For this, we can use a kernel density plot
(ggClimDens <- splnr_plot_climKernelDensity(
- soln = list(dat_solnClimPercentile),
- # names = c("Input 1"),
+ soln = dat_solnClimPercentile,
+ # names = c("Input 1"),
type = "Normal",
legendTitle = "Climate velocity (add unit)",
xAxisLab = "Climate velocity"
@@ -412,8 +414,8 @@ Feature Approach
Feature_Approach <- splnr_climate_featureApproach(
features = datEx_species_bin,
- metric = metric,
- targets = targets,
+ metric = metric,
+ targets = targets,
direction = 1
)
@@ -423,7 +425,8 @@ Feature Approach dplyr::select(
tidyselect::starts_with("Cost_")
),
- join = sf::st_equals) %>%
+ join = sf::st_equals
+ ) %>%
sf::st_join(metric, join = sf::st_equals)
targets <- Feature_Approach$Targets
(ggSoln <- splnr_plot_solution(dat_solnClimFeature) +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
However, we are also interested how climate-smart the selected planning units in the solution actually are. For this, we can use a kernel density plot
(ggClimDens <- splnr_plot_climKernelDensity(
- soln = list(dat_solnClimFeature),
- # names = c("Input 1"),
+ soln = dat_solnClimFeature,
+ # names = c("Input 1"),
type = "Normal",
legendTitle = "Climate velocity (add unit)",
xAxisLab = "Climate velocity"
@@ -481,7 +484,7 @@ Feature Approach
diff --git a/docs/articles/ClimateSmart.md b/docs/articles/ClimateSmart.md
index c51524d4..b55c7147 100644
--- a/docs/articles/ClimateSmart.md
+++ b/docs/articles/ClimateSmart.md
@@ -68,10 +68,12 @@ landmass <- rnaturalearth::ne_countries(scale = "medium", returnclass = "sf") %>
``` r
-PUs <- spatialgridr::get_grid(boundary = Bndry,
- crs = cCRS,
- output = "sf_hex",
- resolution = PU_size)
+PUs <- spatialgridr::get_grid(
+ boundary = Bndry,
+ crs = cCRS,
+ output = "sf_hex",
+ resolution = PU_size
+)
```
### Get the features
@@ -84,21 +86,21 @@ area for the following species:
``` r
Dict <- tibble::tribble(
- ~nameCommon, ~nameVariable, ~category,
- "Green sea turtle", "Chelonia_mydas", "Reptiles",
- "Loggerhead sea turtle", "Caretta_caretta", "Reptiles",
- "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles",
- "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles",
- "Saltwater crocodile", "Crocodylus_porosus", "Reptiles",
- "Humpback whale", "Megaptera_novaeangliae", "Mammals",
- "Common Minke whale", "Balaenoptera_acutorostrata", "Mammals",
- "Dugong", "Dugong_dugon", "Mammals",
- "Grey nurse shark", "Carcharias_taurus", "Sharks and rays",
- "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays",
+ ~nameCommon, ~nameVariable, ~category,
+ "Green sea turtle", "Chelonia_mydas", "Reptiles",
+ "Loggerhead sea turtle", "Caretta_caretta", "Reptiles",
+ "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles",
+ "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles",
+ "Saltwater crocodile", "Crocodylus_porosus", "Reptiles",
+ "Humpback whale", "Megaptera_novaeangliae", "Mammals",
+ "Common Minke whale", "Balaenoptera_acutorostrata", "Mammals",
+ "Dugong", "Dugong_dugon", "Mammals",
+ "Grey nurse shark", "Carcharias_taurus", "Sharks and rays",
+ "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays",
"Great hammerhead shark", "Sphyrna_mokarran",
- "Sharks and rays",
- "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays",
- "Reef manta ray", "Mobula_alfredi", "Sharks and rays",
+ "Sharks and rays",
+ "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays",
+ "Reef manta ray", "Mobula_alfredi", "Sharks and rays",
"Whitetip reef shark", "Triaenodon_obesus", "Sharks and rays",
"Red-footed booby", "Sula_sula", "Birds"
)
@@ -157,10 +159,10 @@ function.
``` r
(ggclim <- splnr_plot_climData(metric, "metric") +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
+ splnr_gg_add(
+ Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
```

@@ -184,10 +186,10 @@ metric <- CoralSeaVelocity %>%
)
(ggclim <- splnr_plot_climData(metric, "metric") +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
+ splnr_gg_add(
+ Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
```

@@ -222,9 +224,9 @@ targets <- datEx_species_bin %>%
CPA_Approach <- splnr_climate_priorityAreaApproach(
features = datEx_species_bin,
- metric = metric,
- targets = targets,
- direction = -1,
+ metric = metric,
+ targets = targets,
+ direction = -1,
refugiaTarget = 1
)
@@ -234,7 +236,8 @@ out_sf <- CPA_Approach$Features %>%
dplyr::select(
tidyselect::starts_with("Cost_")
),
- join = sf::st_equals) %>%
+ join = sf::st_equals
+ ) %>%
sf::st_join(metric, join = sf::st_equals)
targets <- CPA_Approach$Targets
@@ -278,10 +281,10 @@ We can look at the resulting plan using
``` r
(ggSoln <- splnr_plot_solution(dat_solnClim) +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
+ splnr_gg_add(
+ Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
```

@@ -293,8 +296,7 @@ density plot.
``` r
(ggClimDens <- splnr_plot_climKernelDensity(
- soln = list(dat_solnClim),
- # names = c("Input 1"),
+ soln = dat_solnClim,
type = "Normal",
legendTitle = "Climate velocity (add unit)",
xAxisLab = "Climate velocity"
@@ -318,9 +320,9 @@ targets <- datEx_species_bin %>%
Percentile_Approach <- splnr_climate_percentileApproach(
features = datEx_species_bin,
- metric = metric,
- targets = targets,
- direction = -1,
+ metric = metric,
+ targets = targets,
+ direction = -1,
percentile = 35
)
@@ -360,7 +362,7 @@ p2 <- prioritizr::problem(out_sf, usedFeatures, "Cost_None") %>%
prioritizr::add_default_solver(verbose = FALSE)
dat_solnClimPercentile <- prioritizr::solve.ConservationProblem(p2,
- force = TRUE
+ force = TRUE
)
```
@@ -370,10 +372,10 @@ We can look at the resulting plan using
``` r
(ggSoln <- splnr_plot_solution(dat_solnClimPercentile) +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
+ splnr_gg_add(
+ Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
```

@@ -385,8 +387,8 @@ density plot
``` r
(ggClimDens <- splnr_plot_climKernelDensity(
- soln = list(dat_solnClimPercentile),
- # names = c("Input 1"),
+ soln = dat_solnClimPercentile,
+ # names = c("Input 1"),
type = "Normal",
legendTitle = "Climate velocity (add unit)",
xAxisLab = "Climate velocity"
@@ -408,8 +410,8 @@ targets <- datEx_species_bin %>%
Feature_Approach <- splnr_climate_featureApproach(
features = datEx_species_bin,
- metric = metric,
- targets = targets,
+ metric = metric,
+ targets = targets,
direction = 1
)
@@ -419,7 +421,8 @@ out_sf <- Feature_Approach$Features %>%
dplyr::select(
tidyselect::starts_with("Cost_")
),
- join = sf::st_equals) %>%
+ join = sf::st_equals
+ ) %>%
sf::st_join(metric, join = sf::st_equals)
targets <- Feature_Approach$Targets
@@ -453,10 +456,10 @@ dat_solnClimFeature <- prioritizr::solve.ConservationProblem(p3)
``` r
(ggSoln <- splnr_plot_solution(dat_solnClimFeature) +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
+ splnr_gg_add(
+ Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
```

@@ -468,8 +471,8 @@ density plot
``` r
(ggClimDens <- splnr_plot_climKernelDensity(
- soln = list(dat_solnClimFeature),
- # names = c("Input 1"),
+ soln = dat_solnClimFeature,
+ # names = c("Input 1"),
type = "Normal",
legendTitle = "Climate velocity (add unit)",
xAxisLab = "Climate velocity"
diff --git a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-10-1.png
index 0a70bf88..11fe51ad 100644
Binary files a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-10-1.png differ
diff --git a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-11-1.png b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-11-1.png
index beef8d21..e84fb082 100644
Binary files a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-11-1.png and b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-11-1.png differ
diff --git a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-16-1.png b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-16-1.png
index 5b706493..11198e4d 100644
Binary files a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-16-1.png and b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-16-1.png differ
diff --git a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-20-1.png b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-20-1.png
index 3c15f246..284251ee 100644
Binary files a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-20-1.png and b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-20-1.png differ
diff --git a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-23-1.png b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-23-1.png
index 6d6f0c71..05efebc4 100644
Binary files a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-23-1.png and b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-23-1.png differ
diff --git a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-24-1.png b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-24-1.png
index 3593088a..7d47194f 100644
Binary files a/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-24-1.png and b/docs/articles/ClimateSmart_files/figure-html/unnamed-chunk-24-1.png differ
diff --git a/docs/articles/GlobalFishingWatch.html b/docs/articles/GlobalFishingWatch.html
index 835b0103..cfd82d26 100644
--- a/docs/articles/GlobalFishingWatch.html
+++ b/docs/articles/GlobalFishingWatch.html
@@ -25,7 +25,7 @@
spatialplanr
- 0.7.2
+ 0.7.6
@@ -110,7 +110,7 @@ Installationremotes::install_github("GlobalFishingWatch/gfwr")
-region_id <- get_region_id(region = "Australia",
- region_source = "EEZ",
- key = gfwr::gfw_auth())$id[2]region_id <- get_region_id(
+ region = "Australia",
+ region_source = "EEZ",
+ key = gfwr::gfw_auth()
+)$id[2]
The get_raster function gets a raster of fishing effort
from the API and converts the response to a data frame which contains
occurrences for each vessel and for each grid cell (data is binned into
@@ -167,12 +169,14 @@
splnr_get_gfw.
-data_sf_combined <- splnr_get_gfw(region = "Australia",
- start_date = "2019-01-01",
- end_date = "2023-12-31",
- temp_res = "YEARLY",
- spat_res = "LOW",
- compress = FALSE)data_sf_combined <- splnr_get_gfw(
+ region = "Australia",
+ start_date = "2019-01-01",
+ end_date = "2023-12-31",
+ temp_res = "YEARLY",
+ spat_res = "LOW",
+ compress = FALSE
+)
# Check and modify if necessary the spatial reference of data_sf_combined
-data_sf_combined <- sf::st_set_crs(data_sf_combined,
- sf::st_crs(rnaturalearth::ne_coastline(scale = "large")))
+data_sf_combined <- sf::st_set_crs(
+ data_sf_combined,
+ sf::st_crs(rnaturalearth::ne_coastline(scale = "large"))
+)
coast_clipped <- rnaturalearth::ne_coastline(scale = "large") %>%
sf::st_as_sf() %>%
@@ -222,11 +228,13 @@ Year-on-year comparison
# We need to change the temporal range according to our need group by it to display the total fishing hours. <br>
-data_sf_combined <- splnr_get_gfw(region = "Australia",
- start_date = "2019-01-01",
- end_date = "2023-12-31",
- temp_res = "MONTHLY",
- key = gfwr::gfw_auth()) %>%
+data_sf_combined <- splnr_get_gfw(
+ region = "Australia",
+ start_date = "2019-01-01",
+ end_date = "2023-12-31",
+ temp_res = "MONTHLY",
+ key = gfwr::gfw_auth()
+) %>%
dplyr::group_by(Year, Month) %>%
dplyr::summarize(Total_Fishing_Hours = sum(ApparentFishingHrs))

@@ -237,10 +245,12 @@ Fishing gear type
-data_sf_combined <- splnr_get_gfw(region = "Micronesia",
- start_date = "2019-12-31",
- end_date = "2021-01-01",
- temp_res = "MONTHLY")
data_sf_combined <- splnr_get_gfw(
+ region = "Micronesia",
+ start_date = "2019-12-31",
+ end_date = "2021-01-01",
+ temp_res = "MONTHLY"
+)

-library(spatialplanr)
+library(spatialplanr)
set.seed(100)
-PUs <- spatialgridr::get_grid(boundary = Bndry,
- crs = cCRS,
- output = "sf_hex",
- resolution = PU_size)PUs <- spatialgridr::get_grid(
+ boundary = Bndry,
+ crs = cCRS,
+ output = "sf_hex",
+ resolution = PU_size
+)We can also use a customised ggplot theme that can be
passed as a list to splnr_gg_add() and that can then be
used for all plots. For example:
Dict <- tibble::tribble(
- ~nameCommon, ~nameVariable, ~category,
- "Green sea turtle", "Chelonia_mydas", "Reptiles",
- "Loggerhead sea turtle", "Caretta_caretta", "Reptiles",
- "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles",
- "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles",
- "Saltwater crocodile", "Crocodylus_porosus", "Reptiles",
- "Humpback whale", "Megaptera_novaeangliae", "Mammals",
+ ~nameCommon, ~nameVariable, ~category,
+ "Green sea turtle", "Chelonia_mydas", "Reptiles",
+ "Loggerhead sea turtle", "Caretta_caretta", "Reptiles",
+ "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles",
+ "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles",
+ "Saltwater crocodile", "Crocodylus_porosus", "Reptiles",
+ "Humpback whale", "Megaptera_novaeangliae", "Mammals",
"Common Minke whale", "Balaenoptera_acutorostrata",
- "Mammals",
- "Dugong", "Dugong_dugon", "Mammals",
- "Grey nurse shark", "Carcharias_taurus", "Sharks and rays",
- "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays",
+ "Mammals",
+ "Dugong", "Dugong_dugon", "Mammals",
+ "Grey nurse shark", "Carcharias_taurus", "Sharks and rays",
+ "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays",
"Great hammerhead shark", "Sphyrna_mokarran",
- "Sharks and rays",
- "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays",
- "Reef manta ray", "Mobula_alfredi", "Sharks and rays",
+ "Sharks and rays",
+ "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays",
+ "Reef manta ray", "Mobula_alfredi", "Sharks and rays",
"Whitetip reef shark", "Triaenodon_obesus", "Sharks and rays",
"Red-footed booby", "Sula_sula", "Birds"
)
We can also have a look at how well the set target was met.
@@ -509,10 +511,10 @@Within the same zone= c("#c6dbef", "#3182bd", "black"), legendLabels = c("Not selected", "Zone 1", "Zone 2") ) + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - ))



(gg_s8 <- splnr_plot_solution(s8) +
- splnr_gg_add(PUs = PUs, Bndry = Bndry, overlay = landmass, cropOverlay = PUs, ggtheme = splnr_theme))
NOTE: We can also use multiple linear constraints in the same plan, however, this might require a normalization of the input @@ -777,8 +779,8 @@
p10 <- prioritizr::problem(out_sf,
- z10,
- cost_column = c("Cost1", "Cost2")
+ z10,
+ cost_column = c("Cost1", "Cost2")
) %>%
prioritizr::add_min_set_objective() %>%
prioritizr::add_manual_targets(targetAcross) %>%
@@ -818,9 +820,9 @@ Common targets across zones
(gg_s10 <- splnr_plot_solution(s10,
- zones = TRUE,
- colorVals = c("#c6dbef", "#3182bd", "black"),
- legendLabels = c("Not selected", "Zone 1", "Zone 2")
+ zones = TRUE,
+ colorVals = c("#c6dbef", "#3182bd", "black"),
+ legendLabels = c("Not selected", "Zone 1", "Zone 2")
) +
splnr_gg_add(
PUs = PUs, Bndry = Bndry, overlay = landmass,
@@ -857,12 +859,12 @@ Targets across zones with
for 30% of the area.
p11 <- prioritizr::problem(out_sf,
- z10,
- cost_column = c("Cost1", "Cost2")
+ z10,
+ cost_column = c("Cost1", "Cost2")
) %>%
prioritizr::add_min_set_objective() %>%
prioritizr::add_linear_constraints(sum(CostArea[, 1]) * 0.3,
- sense = "<=", CostArea
+ sense = "<=", CostArea
) %>%
prioritizr::add_manual_targets(targetAcross) %>%
prioritizr::add_binary_decisions() %>%
@@ -981,8 +983,8 @@ Targets across some (but not all)
)
p12 <- prioritizr::problem(out_sf,
- z12,
- cost_column = c("Cost1", "Cost2", "Cost3")
+ z12,
+ cost_column = c("Cost1", "Cost2", "Cost3")
) %>%
prioritizr::add_min_set_objective() %>%
prioritizr::add_manual_targets(targetAcrossSome) %>%
@@ -1089,7 +1091,7 @@ Longer-term
- Site built with pkgdown 2.2.0.
+ Site built with pkgdown 2.2.1.
diff --git a/docs/articles/MultipleUse.md b/docs/articles/MultipleUse.md
index 4992e8ab..9f5c4449 100644
--- a/docs/articles/MultipleUse.md
+++ b/docs/articles/MultipleUse.md
@@ -61,10 +61,12 @@ landmass <- rnaturalearth::ne_countries(
``` r
-PUs <- spatialgridr::get_grid(boundary = Bndry,
- crs = cCRS,
- output = "sf_hex",
- resolution = PU_size)
+PUs <- spatialgridr::get_grid(
+ boundary = Bndry,
+ crs = cCRS,
+ output = "sf_hex",
+ resolution = PU_size
+)
```
We can also use a customised `ggplot` theme that can be passed as a list
@@ -97,22 +99,22 @@ area for the following species:
``` r
Dict <- tibble::tribble(
- ~nameCommon, ~nameVariable, ~category,
- "Green sea turtle", "Chelonia_mydas", "Reptiles",
- "Loggerhead sea turtle", "Caretta_caretta", "Reptiles",
- "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles",
- "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles",
- "Saltwater crocodile", "Crocodylus_porosus", "Reptiles",
- "Humpback whale", "Megaptera_novaeangliae", "Mammals",
+ ~nameCommon, ~nameVariable, ~category,
+ "Green sea turtle", "Chelonia_mydas", "Reptiles",
+ "Loggerhead sea turtle", "Caretta_caretta", "Reptiles",
+ "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles",
+ "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles",
+ "Saltwater crocodile", "Crocodylus_porosus", "Reptiles",
+ "Humpback whale", "Megaptera_novaeangliae", "Mammals",
"Common Minke whale", "Balaenoptera_acutorostrata",
- "Mammals",
- "Dugong", "Dugong_dugon", "Mammals",
- "Grey nurse shark", "Carcharias_taurus", "Sharks and rays",
- "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays",
+ "Mammals",
+ "Dugong", "Dugong_dugon", "Mammals",
+ "Grey nurse shark", "Carcharias_taurus", "Sharks and rays",
+ "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays",
"Great hammerhead shark", "Sphyrna_mokarran",
- "Sharks and rays",
- "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays",
- "Reef manta ray", "Mobula_alfredi", "Sharks and rays",
+ "Sharks and rays",
+ "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays",
+ "Reef manta ray", "Mobula_alfredi", "Sharks and rays",
"Whitetip reef shark", "Triaenodon_obesus", "Sharks and rays",
"Red-footed booby", "Sula_sula", "Birds"
)
@@ -171,7 +173,7 @@ s1 <- p1 %>%
prioritizr::solve.ConservationProblem()
(ggSoln <- splnr_plot_solution(s1) +
- splnr_gg_add(PUs = PUs, Bndry = Bndry, overlay = landmass, cropOverlay = PUs, ggtheme = splnr_theme))
+ splnr_gg_add(PUs = PUs, Bndry = Bndry, overlay = landmass, cropOverlay = PUs, ggtheme = splnr_theme))
```

@@ -524,10 +526,10 @@ s4 <- p4 %>%
colorVals = c("#c6dbef", "#3182bd", "black"),
legendLabels = c("Not selected", "Zone 1", "Zone 2")
) +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
+ splnr_gg_add(
+ PUs = PUs, Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
```

@@ -571,10 +573,10 @@ s5 <- p5 %>%
colorVals = c("#c6dbef", "#3182bd", "black"),
legendLabels = c("Not selected", "Zone 1", "Zone 2")
) +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
+ splnr_gg_add(
+ PUs = PUs, Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
```

@@ -594,7 +596,7 @@ specific format, so we first prepare the MPA data.
mpas <- MPAsCoralSea %>%
dplyr::mutate(zone = "zone 1") %>%
dplyr::rename(status = wdpa) %>%
- tibble::rowid_to_column("pu") %>%
+ tibble::rowid_to_column("pu") %>%
sf::st_drop_geometry() %>%
tibble::tibble() %>%
dplyr::filter(status == 1)
@@ -694,10 +696,10 @@ s7 <- p7 %>%
colorVals = c("#c6dbef", "#3182bd", "black"),
legendLabels = c("Not selected", "Zone 1", "Zone 2")
) +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
+ splnr_gg_add(
+ PUs = PUs, Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
```

@@ -743,7 +745,7 @@ p8 <- prioritizr::problem(
prioritizr::add_min_set_objective() %>%
prioritizr::add_relative_targets(target8) %>%
prioritizr::add_linear_constraints(sum(costRandom$CostR) * 0.1,
- sense = "<=", costRandom$CostR
+ sense = "<=", costRandom$CostR
) %>%
prioritizr::add_binary_decisions() %>%
prioritizr::add_default_solver(verbose = FALSE)
@@ -765,7 +767,7 @@ We can visualise the solution again:
``` r
(gg_s8 <- splnr_plot_solution(s8) +
- splnr_gg_add(PUs = PUs, Bndry = Bndry, overlay = landmass, cropOverlay = PUs, ggtheme = splnr_theme))
+ splnr_gg_add(PUs = PUs, Bndry = Bndry, overlay = landmass, cropOverlay = PUs, ggtheme = splnr_theme))
```

@@ -843,8 +845,8 @@ layer for `zone2` being three times as costly as for `zone1`.
``` r
p10 <- prioritizr::problem(out_sf,
- z10,
- cost_column = c("Cost1", "Cost2")
+ z10,
+ cost_column = c("Cost1", "Cost2")
) %>%
prioritizr::add_min_set_objective() %>%
prioritizr::add_manual_targets(targetAcross) %>%
@@ -892,9 +894,9 @@ costly.
``` r
(gg_s10 <- splnr_plot_solution(s10,
- zones = TRUE,
- colorVals = c("#c6dbef", "#3182bd", "black"),
- legendLabels = c("Not selected", "Zone 1", "Zone 2")
+ zones = TRUE,
+ colorVals = c("#c6dbef", "#3182bd", "black"),
+ legendLabels = c("Not selected", "Zone 1", "Zone 2")
) +
splnr_gg_add(
PUs = PUs, Bndry = Bndry, overlay = landmass,
@@ -937,12 +939,12 @@ We then define the conservation problem and add a linear constraint for
``` r
p11 <- prioritizr::problem(out_sf,
- z10,
- cost_column = c("Cost1", "Cost2")
+ z10,
+ cost_column = c("Cost1", "Cost2")
) %>%
prioritizr::add_min_set_objective() %>%
prioritizr::add_linear_constraints(sum(CostArea[, 1]) * 0.3,
- sense = "<=", CostArea
+ sense = "<=", CostArea
) %>%
prioritizr::add_manual_targets(targetAcross) %>%
prioritizr::add_binary_decisions() %>%
@@ -1083,8 +1085,8 @@ out_sf <- datSpecZone1 %>%
``` r
p12 <- prioritizr::problem(out_sf,
- z12,
- cost_column = c("Cost1", "Cost2", "Cost3")
+ z12,
+ cost_column = c("Cost1", "Cost2", "Cost3")
) %>%
prioritizr::add_min_set_objective() %>%
prioritizr::add_manual_targets(targetAcrossSome) %>%
diff --git a/docs/articles/MultipleUse_files/figure-html/unnamed-chunk-30-1.png b/docs/articles/MultipleUse_files/figure-html/unnamed-chunk-30-1.png
index fb373444..1afa44ff 100644
Binary files a/docs/articles/MultipleUse_files/figure-html/unnamed-chunk-30-1.png and b/docs/articles/MultipleUse_files/figure-html/unnamed-chunk-30-1.png differ
diff --git a/docs/articles/index.html b/docs/articles/index.html
index 424f7818..cc0d01b8 100644
--- a/docs/articles/index.html
+++ b/docs/articles/index.html
@@ -7,7 +7,7 @@
spatialplanr
- 0.7.2
+ 0.7.6
@@ -57,7 +57,7 @@ All vignettes
diff --git a/docs/articles/spatialplanr.html b/docs/articles/spatialplanr.html
index 501e74cb..29a312cf 100644
--- a/docs/articles/spatialplanr.html
+++ b/docs/articles/spatialplanr.html
@@ -25,7 +25,7 @@
spatialplanr
- 0.7.2
+ 0.7.6
@@ -72,7 +72,7 @@
+library(spatialplanr)
Overview
@@ -121,23 +121,25 @@ Analysis RegionCreate Planning Units
-PUs <- spatialgridr::get_grid(boundary = Bndry,
- crs = cCRS,
- output = "sf_hex",
- resolution = PU_size)
+PUs <- spatialgridr::get_grid(
+ boundary = Bndry,
+ crs = cCRS,
+ output = "sf_hex",
+ resolution = PU_size
+)
We can check what the PUs look like
(ggPU <- splnr_plot(df = PUs) +
- ggplot2::theme_bw()) # Plot Planning Units
+ ggplot2::theme_bw()) # Plot Planning Units

If we want to add additional properties to our map, for example
landmass or the boundary, we can use splnr_gg_add().
(ggPU <- splnr_plot(df = PUs) +
- splnr_gg_add(
- Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = "Default"
- ))
We can also use a customised ggplpot theme that can be
passed as a list to splnr_gg_add() and that can then be
@@ -156,10 +158,10 @@

Dict <- tibble::tribble(
- ~nameCommon, ~nameVariable, ~category,
- "Green sea turtle", "Chelonia_mydas", "Reptiles",
- "Loggerhead sea turtle", "Caretta_caretta", "Reptiles",
- "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles",
- "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles",
- "Saltwater crocodile", "Crocodylus_porosus", "Reptiles",
- "Humpback whale", "Megaptera_novaeangliae", "Mammals",
- "Common Minke whale", "Balaenoptera_acutorostrata", "Mammals",
- "Dugong", "Dugong_dugon", "Mammals",
- "Grey nurse shark", "Carcharias_taurus", "Sharks and rays",
- "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays",
- "Great hammerhead shark", "Sphyrna_mokarran", "Sharks and rays",
- "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays",
- "Reef manta ray", "Mobula_alfredi", "Sharks and rays",
+ ~nameCommon, ~nameVariable, ~category,
+ "Green sea turtle", "Chelonia_mydas", "Reptiles",
+ "Loggerhead sea turtle", "Caretta_caretta", "Reptiles",
+ "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles",
+ "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles",
+ "Saltwater crocodile", "Crocodylus_porosus", "Reptiles",
+ "Humpback whale", "Megaptera_novaeangliae", "Mammals",
+ "Common Minke whale", "Balaenoptera_acutorostrata", "Mammals",
+ "Dugong", "Dugong_dugon", "Mammals",
+ "Grey nurse shark", "Carcharias_taurus", "Sharks and rays",
+ "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays",
+ "Great hammerhead shark", "Sphyrna_mokarran", "Sharks and rays",
+ "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays",
+ "Reef manta ray", "Mobula_alfredi", "Sharks and rays",
"Whitetip reef shark", "Triaenodon_obesus", "Sharks and rays",
"Red-footed booby", "Sula_sula", "Birds"
)
-(ggFeatNo <- splnr_plot(df = datEx_species_bin,
- colNames = colnames(datEx_species_bin %>%
- sf::st_drop_geometry()),
- plotTitle = "",
- legendTitle = "Number of features") +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))(ggFeatNo <- splnr_plot(
+ df = datEx_species_bin,
+ colNames = colnames(datEx_species_bin %>%
+ sf::st_drop_geometry()),
+ plotTitle = "",
+ legendTitle = "Number of features"
+) +
+ splnr_gg_add(
+ PUs = PUs, Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
out_sf$Cost_None <- 1
-(ggCost <- splnr_plot(out_sf, colNames = "Cost_None",
- legendTitle = "Cost", legendLabels = "1") +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
Apparent fishing hours per
coordinates.
-gfw_data <- splnr_get_gfw(region = 'Australia',
- start_date = "2022-01-01",
- end_date = "2022-12-31",
- temp_res = "yearly",
- cCRS = cCRS,
- compress = TRUE) %>%
+gfw_data <- splnr_get_gfw(
+ region = "Australia",
+ start_date = "2022-01-01",
+ end_date = "2022-12-31",
+ temp_res = "yearly",
+ cCRS = cCRS,
+ compress = TRUE
+) %>%
sf::st_interpolate_aw(PUs, extensive = TRUE)
out_sf$Apparent.Fishing.Hours <- 0 # Add column to PUs
-out_sf$Apparent.Fishing.Hours[as.numeric(rownames(PUs))] <-
+out_sf$Apparent.Fishing.Hours[as.numeric(rownames(PUs))] <-
gfw_data$Apparent.Fishing.Hours # Put corresponding data in PUs
(ggCost <- splnr_plot(out_sf, colNames = "Apparent.Fishing.Hours") +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
-(ggSoln <- splnr_plot(datEx_soln,
- colNames = "solution_1",
- legendTitle = "Solution",
- legendLabels = c("0","1")) +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))(ggSoln <- splnr_plot(datEx_soln,
+ colNames = "solution_1",
+ legendTitle = "Solution",
+ legendLabels = c("0", "1")
+) +
+ splnr_gg_add(
+ PUs = PUs, Bndry = Bndry, overlay = landmass,
+ cropOverlay = PUs, ggtheme = splnr_theme
+ ))
This plot shows the optimal solution for the planning region that meets the selected targets for the chosen features for the smallest area @@ -406,25 +415,25 @@
dfTarget <- splnr_get_featureRep(datEx_soln, datEx_problem,
- climsmart = FALSE,
- solnCol = "solution_1"
+ climsmart = FALSE,
+ solnCol = "solution_1"
)
-(ggTarget <- splnr_plot_featureRep(dfTarget,
- category = Dict,
- renameFeatures = TRUE,
- namesToReplace = Dict,
- categoryFeatureCol = "nameCommon",
- nr = 1, showTarget = TRUE,
+(ggTarget <- splnr_plot_featureRep(dfTarget,
+ category = Dict,
+ renameFeatures = TRUE,
+ namesToReplace = Dict,
+ categoryFeatureCol = "nameCommon",
+ nr = 1, showTarget = TRUE,
))
For a circular bar plot, one additional step of data preparation needs to be done.
dfTargetCirc <- dfTarget %>%
-dplyr::select("feature", "value", "group") %>%
-na.omit()
+ dplyr::select("feature", "value", "group") %>%
+ na.omit()
colors <- c(
"important" = "darkgreen",
@@ -495,10 +504,10 @@ Comparing Spatial Plans dplyr::mutate(wdpa = as.logical(wdpa))
(ggMPA <- splnr_plot(MPAsCoralSea, "wdpa") +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
We will also include targets based on IUCN categories to prioritise species with an IUCN status of:
@@ -514,8 +523,7 @@
-
-minTarget <- 0.1
+minTarget <- 0.1
maxTarget <- 0.2
# Create inverse area target
@@ -528,8 +536,7 @@ Comparing Spatial Plans
-
-IUCN_IA_Targets <- IA_Targets %>%
+IUCN_IA_Targets <- IA_Targets %>%
splnr_get_IUCNRedList(species_col = "Species") %>% # Add RL data to the df
splnr_targets_byIUCN(IUCN_target = 0.3)
Note: Accessing the IUCN database requires a login
@@ -553,10 +560,10 @@
Set up second conservation problem prioritizr::solve.ConservationProblem()
(ggSoln2 <- splnr_plot_solution(datEx_soln2) +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))

But we locked-in areas that were already existing Marine Protected Areas (MPAs). If we want to show the overlap between the selected @@ -564,24 +571,24 @@
(splnr_plot_solution(datEx_soln2) +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, lockIn = MPAsCoralSea,
- nameLockIn = "wdpa", typeLockIn = "Full",
- colorLockIn = "lightgrey", alphaLockIn = 0.2, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
If we instead only want to see the contours of the locked-in areas we
can set typeLockIn = "Contours" in
splnr_gg_add().
(splnr_plot_solution(datEx_soln2) +
- splnr_gg_add(
- lockIn = MPAsCoralSea,
- nameLockIn = "wdpa", typeLockIn = "Contours",
- colorLockIn = "lightgrey", alphaLockIn = 0.2, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
(ggComp <- splnr_plot_comparison(datEx_soln, datEx_soln2) +
- splnr_gg_add(
- PUs = PUs, Bndry = Bndry, overlay = landmass,
- cropOverlay = PUs, ggtheme = splnr_theme
- ))
This plot shows how the first solution (without current MPAs) differs from the second solution (including current MPAs. The categorical map @@ -601,11 +608,11 @@
CorrMat <- splnr_get_kappaCorrData(list(datEx_soln, datEx_soln2),
- name_sol = c("soln1", "soln2")
+ name_sol = c("soln1", "soln2")
)
(ggCorr <- splnr_plot_corrMat(CorrMat,
- AxisLabels = c("Solution 1", "Solution 2")
+ AxisLabels = c("Solution 1", "Solution 2")
))

The correlation matrix shows the similarity as the Cohen’s Kappa @@ -633,10 +640,10 @@

Site built with pkgdown 2.2.0.
+Site built with pkgdown 2.2.1.
diff --git a/docs/articles/spatialplanr.md b/docs/articles/spatialplanr.md index d14731eb..20b0570c 100644 --- a/docs/articles/spatialplanr.md +++ b/docs/articles/spatialplanr.md @@ -73,10 +73,12 @@ landmass <- rnaturalearth::ne_countries( ``` r -PUs <- spatialgridr::get_grid(boundary = Bndry, - crs = cCRS, - output = "sf_hex", - resolution = PU_size) +PUs <- spatialgridr::get_grid( + boundary = Bndry, + crs = cCRS, + output = "sf_hex", + resolution = PU_size +) ``` We can check what the PUs look like @@ -84,7 +86,7 @@ We can check what the PUs look like ``` r (ggPU <- splnr_plot(df = PUs) + - ggplot2::theme_bw()) # Plot Planning Units + ggplot2::theme_bw()) # Plot Planning Units ```  @@ -96,10 +98,10 @@ or the boundary, we can use ``` r (ggPU <- splnr_plot(df = PUs) + - splnr_gg_add( - Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = "Default" - )) + splnr_gg_add( + Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = "Default" + )) ```  @@ -124,10 +126,10 @@ splnr_theme <- list( ) (ggPU <- splnr_plot(PUs) + - splnr_gg_add( - Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) + splnr_gg_add( + Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -142,20 +144,20 @@ area for the following species: ``` r Dict <- tibble::tribble( - ~nameCommon, ~nameVariable, ~category, - "Green sea turtle", "Chelonia_mydas", "Reptiles", - "Loggerhead sea turtle", "Caretta_caretta", "Reptiles", - "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles", - "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles", - "Saltwater crocodile", "Crocodylus_porosus", "Reptiles", - "Humpback whale", "Megaptera_novaeangliae", "Mammals", - "Common Minke whale", "Balaenoptera_acutorostrata", "Mammals", - "Dugong", "Dugong_dugon", "Mammals", - "Grey nurse shark", "Carcharias_taurus", "Sharks and rays", - "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays", - "Great hammerhead shark", "Sphyrna_mokarran", "Sharks and rays", - "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays", - "Reef manta ray", "Mobula_alfredi", "Sharks and rays", + ~nameCommon, ~nameVariable, ~category, + "Green sea turtle", "Chelonia_mydas", "Reptiles", + "Loggerhead sea turtle", "Caretta_caretta", "Reptiles", + "Hawksbill sea turtle", "Eretmochelys_imbricata", "Reptiles", + "Olive ridley sea turtle", "Lepidochelys_olivacea", "Reptiles", + "Saltwater crocodile", "Crocodylus_porosus", "Reptiles", + "Humpback whale", "Megaptera_novaeangliae", "Mammals", + "Common Minke whale", "Balaenoptera_acutorostrata", "Mammals", + "Dugong", "Dugong_dugon", "Mammals", + "Grey nurse shark", "Carcharias_taurus", "Sharks and rays", + "Tiger shark", "Galeocerdo_cuvier", "Sharks and rays", + "Great hammerhead shark", "Sphyrna_mokarran", "Sharks and rays", + "Giant oceanic manta ray", "Mobula_birostris", "Sharks and rays", + "Reef manta ray", "Mobula_alfredi", "Sharks and rays", "Whitetip reef shark", "Triaenodon_obesus", "Sharks and rays", "Red-footed booby", "Sula_sula", "Birds" ) @@ -233,15 +235,17 @@ Planning Unit of the study region. ``` r -(ggFeatNo <- splnr_plot(df = datEx_species_bin, - colNames = colnames(datEx_species_bin %>% - sf::st_drop_geometry()), - plotTitle = "", - legendTitle = "Number of features") + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) +(ggFeatNo <- splnr_plot( + df = datEx_species_bin, + colNames = colnames(datEx_species_bin %>% + sf::st_drop_geometry()), + plotTitle = "", + legendTitle = "Number of features" +) + + splnr_gg_add( + PUs = PUs, Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -275,12 +279,14 @@ units are assigned an equal cost of 1. ``` r out_sf$Cost_None <- 1 -(ggCost <- splnr_plot(out_sf, colNames = "Cost_None", - legendTitle = "Cost", legendLabels = "1") + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) +(ggCost <- splnr_plot(out_sf, + colNames = "Cost_None", + legendTitle = "Cost", legendLabels = "1" +) + + splnr_gg_add( + PUs = PUs, Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -295,24 +301,26 @@ world, we set here the parameter `compress` as `TRUE` to recover the ``` r -gfw_data <- splnr_get_gfw(region = 'Australia', - start_date = "2022-01-01", - end_date = "2022-12-31", - temp_res = "yearly", - cCRS = cCRS, - compress = TRUE) %>% +gfw_data <- splnr_get_gfw( + region = "Australia", + start_date = "2022-01-01", + end_date = "2022-12-31", + temp_res = "yearly", + cCRS = cCRS, + compress = TRUE +) %>% sf::st_interpolate_aw(PUs, extensive = TRUE) out_sf$Apparent.Fishing.Hours <- 0 # Add column to PUs -out_sf$Apparent.Fishing.Hours[as.numeric(rownames(PUs))] <- +out_sf$Apparent.Fishing.Hours[as.numeric(rownames(PUs))] <- gfw_data$Apparent.Fishing.Hours # Put corresponding data in PUs (ggCost <- splnr_plot(out_sf, colNames = "Apparent.Fishing.Hours") + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) + splnr_gg_add( + PUs = PUs, Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ``` ###### Other features @@ -369,14 +377,15 @@ importance scores ``` r -(ggSoln <- splnr_plot(datEx_soln, - colNames = "solution_1", - legendTitle = "Solution", - legendLabels = c("0","1")) + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) +(ggSoln <- splnr_plot(datEx_soln, + colNames = "solution_1", + legendTitle = "Solution", + legendLabels = c("0", "1") +) + + splnr_gg_add( + PUs = PUs, Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -416,17 +425,17 @@ region. ``` r dfTarget <- splnr_get_featureRep(datEx_soln, datEx_problem, - climsmart = FALSE, - solnCol = "solution_1" + climsmart = FALSE, + solnCol = "solution_1" ) -(ggTarget <- splnr_plot_featureRep(dfTarget, - category = Dict, - renameFeatures = TRUE, - namesToReplace = Dict, - categoryFeatureCol = "nameCommon", - nr = 1, showTarget = TRUE, +(ggTarget <- splnr_plot_featureRep(dfTarget, + category = Dict, + renameFeatures = TRUE, + namesToReplace = Dict, + categoryFeatureCol = "nameCommon", + nr = 1, showTarget = TRUE, )) ``` @@ -438,8 +447,8 @@ to be done. ``` r dfTargetCirc <- dfTarget %>% -dplyr::select("feature", "value", "group") %>% -na.omit() + dplyr::select("feature", "value", "group") %>% + na.omit() colors <- c( "important" = "darkgreen", @@ -521,10 +530,10 @@ LockedIn <- splnr_get_MPAs(PUs, "Australia") %>% ``` r (ggMPA <- splnr_plot(MPAsCoralSea, "wdpa") + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) + splnr_gg_add( + PUs = PUs, Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -545,7 +554,6 @@ a lower target. ``` r - minTarget <- 0.1 maxTarget <- 0.2 @@ -563,7 +571,6 @@ level on the IUCN Red List(“EX”, “EW”, “CR”, “EN”, “VU”). ``` r - IUCN_IA_Targets <- IA_Targets %>% splnr_get_IUCNRedList(species_col = "Species") %>% # Add RL data to the df splnr_targets_byIUCN(IUCN_target = 0.3) @@ -591,10 +598,10 @@ datEx_soln2 <- datEx_problem2 %>% prioritizr::solve.ConservationProblem() (ggSoln2 <- splnr_plot_solution(datEx_soln2) + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) + splnr_gg_add( + PUs = PUs, Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -608,12 +615,12 @@ function. ``` r (splnr_plot_solution(datEx_soln2) + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, lockIn = MPAsCoralSea, - nameLockIn = "wdpa", typeLockIn = "Full", - colorLockIn = "lightgrey", alphaLockIn = 0.2, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) + splnr_gg_add( + PUs = PUs, Bndry = Bndry, lockIn = MPAsCoralSea, + nameLockIn = "wdpa", typeLockIn = "Full", + colorLockIn = "lightgrey", alphaLockIn = 0.2, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -625,12 +632,12 @@ can set `typeLockIn = "Contours"` in ``` r (splnr_plot_solution(datEx_soln2) + - splnr_gg_add( - lockIn = MPAsCoralSea, - nameLockIn = "wdpa", typeLockIn = "Contours", - colorLockIn = "lightgrey", alphaLockIn = 0.2, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) + splnr_gg_add( + lockIn = MPAsCoralSea, + nameLockIn = "wdpa", typeLockIn = "Contours", + colorLockIn = "lightgrey", alphaLockIn = 0.2, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -640,10 +647,10 @@ can set `typeLockIn = "Contours"` in ``` r (ggComp <- splnr_plot_comparison(datEx_soln, datEx_soln2) + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) + splnr_gg_add( + PUs = PUs, Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  @@ -657,11 +664,11 @@ selected in both solutions (grey). ``` r CorrMat <- splnr_get_kappaCorrData(list(datEx_soln, datEx_soln2), - name_sol = c("soln1", "soln2") + name_sol = c("soln1", "soln2") ) (ggCorr <- splnr_plot_corrMat(CorrMat, - AxisLabels = c("Solution 1", "Solution 2") + AxisLabels = c("Solution 1", "Solution 2") )) ``` @@ -693,10 +700,10 @@ selFreq <- datEx_soln_portfolio %>% # calculate selection frequency dplyr::select(selFreq) (ggselFreq <- splnr_plot_selectionFreq(selFreq) + - splnr_gg_add( - PUs = PUs, Bndry = Bndry, overlay = landmass, - cropOverlay = PUs, ggtheme = splnr_theme - )) + splnr_gg_add( + PUs = PUs, Bndry = Bndry, overlay = landmass, + cropOverlay = PUs, ggtheme = splnr_theme + )) ```  diff --git a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-10-1.png b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-10-1.png index 2c268726..4cd69cf2 100644 Binary files a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-10-1.png and b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-10-1.png differ diff --git a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-16-1.png b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-16-1.png index 08298a8d..68e4f91a 100644 Binary files a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-16-1.png and b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-16-1.png differ diff --git a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-27-1.png b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-27-1.png index 5cada725..6e137f7a 100644 Binary files a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-27-1.png and b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-27-1.png differ diff --git a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-28-1.png b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-28-1.png index bc786304..0e9c2d32 100644 Binary files a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-28-1.png and b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-28-1.png differ diff --git a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-30-1.png b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-30-1.png index a99c840a..87f82fc9 100644 Binary files a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-30-1.png and b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-30-1.png differ diff --git a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-36-1.png b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-36-1.png index fc7c81f3..40b7fdc5 100644 Binary files a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-36-1.png and b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-36-1.png differ diff --git a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-39-1.png b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-39-1.png index 07329067..906c7d6d 100644 Binary files a/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-39-1.png and b/docs/articles/spatialplanr_files/figure-html/unnamed-chunk-39-1.png differ diff --git a/docs/authors.html b/docs/authors.html index cfdf89f6..b05709d6 100644 --- a/docs/authors.html +++ b/docs/authors.html @@ -7,7 +7,7 @@ spatialplanr - 0.7.2 + 0.7.6Everett J, Neubert S (2026). spatialplanr: Help files for prioritzr Spatial Planning projects. -R package version 0.7.2, https://github.com/SpatialPlanning/spatialplanr. +R package version 0.7.6, https://mathmarecol.github.io/spatialplanr.
@Manual{,
title = {spatialplanr: Help files for prioritzr Spatial Planning projects},
author = {Jason D. Everett and Sandra Neubert},
year = {2026},
- note = {R package version 0.7.2},
- url = {https://github.com/SpatialPlanning/spatialplanr},
+ note = {R package version 0.7.6},
+ url = {https://mathmarecol.github.io/spatialplanr},
}
@@ -75,7 +75,7 @@ Site built with pkgdown 2.2.0.
+Site built with pkgdown 2.2.1.
diff --git a/docs/reference/pipe.html b/docs/reference/pipe.html index 369c2171..1e56b250 100644 --- a/docs/reference/pipe.html +++ b/docs/reference/pipe.html @@ -7,7 +7,7 @@ spatialplanr - 0.7.2 + 0.7.6A numeric value or a named numeric vector of cutoffs.
If a single unnamed numeric value, it's applied to all numeric columns.
If a named numeric vector, names must correspond to numeric column names in features.
All cutoff values must be between 0 and 1.
One of:
A single unnamed numeric value in [0, 1] — applied to all
+numeric columns.
A single unnamed function that accepts a numeric vector and returns
+a single numeric in [0, 1] — called independently per column
+with the non-NA values of that column.
A named numeric vector — names must match numeric column names in
+features; each value is applied to its named column only.
A named list of numerics and/or functions — names must match
+numeric column names in features; each entry is applied to its
+named column only.
A logical value (TRUE or FALSE). If TRUE, values below
-the Cutoffs are converted to 1 (and others to 0). If FALSE (default),
-values at or above the Cutoffs are converted to 1.
1 (and others to 0). If FALSE
+(default), values at or above the threshold are converted to 1.
-# Example 1: Single cutoff (0.5) applied to all numeric feature columns
-# (Spp1_Prob, Spp2_Prob, and Cost will be binarized based on 0.5)
+# Example 1: Single numeric cutoff applied to all numeric feature columns
df_single_cutoff <- splnr_apply_cutoffs(dat_species_prob, Cutoffs = 0.5)
#> Applying single cutoff of 0.5 to all numeric feature columns.
print(df_single_cutoff)
@@ -137,15 +152,48 @@ Examples#> 10 ((118 -50, 120 -50, 120 -48, 118 -48, 118 -50)) 1 0 1 0 1
#> # ℹ 770 more rows
-# Example 2: Named cutoffs for specific columns
-# Spp1_Prob >= 0.6 becomes 1, Spp2_Prob >= 0.4 becomes 1
+# Example 2: Single function cutoff applied to all numeric feature columns
+# Each column independently receives the 99th-percentile of its own values
+# as its threshold.
+df_fn_cutoff <- splnr_apply_cutoffs(
+ dat_species_prob,
+ Cutoffs = \(x) quantile(x, 0.99)
+)
+#> Applying function-based cutoff independently to each numeric feature column.
+#> Column 'Spp1': resolved threshold = 0.985033159928862
+#> Column 'Spp2': resolved threshold = 0.993628154252656
+#> Column 'Spp3': resolved threshold = 0.992002531981561
+#> Column 'Spp4': resolved threshold = 0.987106560785323
+#> Column 'Spp5': resolved threshold = 0.986841972519178
+print(df_fn_cutoff)
+#> Simple feature collection with 780 features and 5 fields
+#> Geometry type: POLYGON
+#> Dimension: XY
+#> Bounding box: xmin: 100 ymin: -50 xmax: 160 ymax: 2
+#> Geodetic CRS: WGS 84
+#> # A tibble: 780 × 6
+#> geometry Spp1 Spp2 Spp3 Spp4 Spp5
+#> <POLYGON [°]> <dbl> <dbl> <dbl> <dbl> <dbl>
+#> 1 ((100 -50, 102 -50, 102 -48, 100 -48, 100 -50)) 0 0 0 0 0
+#> 2 ((102 -50, 104 -50, 104 -48, 102 -48, 102 -50)) 0 0 0 0 0
+#> 3 ((104 -50, 106 -50, 106 -48, 104 -48, 104 -50)) 0 0 0 0 0
+#> 4 ((106 -50, 108 -50, 108 -48, 106 -48, 106 -50)) 0 0 0 0 0
+#> 5 ((108 -50, 110 -50, 110 -48, 108 -48, 108 -50)) 0 0 0 0 0
+#> 6 ((110 -50, 112 -50, 112 -48, 110 -48, 110 -50)) 0 0 0 0 0
+#> 7 ((112 -50, 114 -50, 114 -48, 112 -48, 112 -50)) 0 0 0 0 0
+#> 8 ((114 -50, 116 -50, 116 -48, 114 -48, 114 -50)) 0 0 0 0 0
+#> 9 ((116 -50, 118 -50, 118 -48, 116 -48, 116 -50)) 0 0 0 0 0
+#> 10 ((118 -50, 120 -50, 120 -48, 118 -48, 118 -50)) 0 0 0 0 0
+#> # ℹ 770 more rows
+
+# Example 3: Named numeric cutoffs for specific columns
df_named_cutoffs <- splnr_apply_cutoffs(
dat_species_prob,
Cutoffs = c("Spp1" = 0.6, "Spp2" = 0.4)
)
#> Applying named cutoffs to specific feature columns.
-#> Applying cutoff 0.6 to column 'Spp1'.
-#> Applying cutoff 0.4 to column 'Spp2'.
+#> Column 'Spp1': resolved threshold = 0.6
+#> Column 'Spp2': resolved threshold = 0.4
print(df_named_cutoffs)
#> Simple feature collection with 780 features and 5 fields
#> Geometry type: POLYGON
@@ -167,11 +215,42 @@ Examples#> 10 ((118 -50, 120 -50, 120 -48, 118 -48, 118… 1 1 0.695 0.00687 0.815
#> # ℹ 770 more rows
-# Example 3: Single cutoff (0.5) with inverse logic
-# Values BELOW 0.5 become 1.
+# Example 4: Named list mixing fixed and function-based cutoffs
+df_mixed_cutoffs <- splnr_apply_cutoffs(
+ dat_species_prob,
+ Cutoffs = list(
+ "Spp1" = 0.5,
+ "Spp2" = \(x) quantile(x, 0.99)
+ )
+)
+#> Applying named cutoffs to specific feature columns.
+#> Column 'Spp1': resolved threshold = 0.5
+#> Column 'Spp2': resolved threshold = 0.993628154252656
+print(df_mixed_cutoffs)
+#> Simple feature collection with 780 features and 5 fields
+#> Geometry type: POLYGON
+#> Dimension: XY
+#> Bounding box: xmin: 100 ymin: -50 xmax: 160 ymax: 2
+#> Geodetic CRS: WGS 84
+#> # A tibble: 780 × 6
+#> geometry Spp1 Spp2 Spp3 Spp4 Spp5
+#> <POLYGON [°]> <dbl> <dbl> <dbl> <dbl> <dbl>
+#> 1 ((100 -50, 102 -50, 102 -48, 100 -48, 100… 1 0 0.0969 0.435 0.0418
+#> 2 ((102 -50, 104 -50, 104 -48, 102 -48, 102… 1 0 0.504 0.503 0.360
+#> 3 ((104 -50, 106 -50, 106 -48, 104 -48, 104… 0 0 0.285 0.755 0.653
+#> 4 ((106 -50, 108 -50, 108 -48, 106 -48, 106… 1 0 0.564 0.503 0.529
+#> 5 ((108 -50, 110 -50, 110 -48, 108 -48, 108… 0 0 0.150 0.863 0.753
+#> 6 ((110 -50, 112 -50, 112 -48, 110 -48, 110… 1 0 0.807 0.458 0.374
+#> 7 ((112 -50, 114 -50, 114 -48, 112 -48, 112… 0 0 0.00963 0.102 0.114
+#> 8 ((114 -50, 116 -50, 116 -48, 114 -48, 114… 0 0 0.481 0.231 0.764
+#> 9 ((116 -50, 118 -50, 118 -48, 116 -48, 116… 0 0 0.552 0.00978 0.552
+#> 10 ((118 -50, 120 -50, 120 -48, 118 -48, 118… 1 0 0.695 0.00687 0.815
+#> # ℹ 770 more rows
+
+# Example 5: Single numeric cutoff with inverse logic
df_inverse_cutoff <- splnr_apply_cutoffs(dat_species_prob, Cutoffs = 0.5, inverse = TRUE)
#> Applying single cutoff of 0.5 to all numeric feature columns.
-#> Inverse logic applied: values below cutoff will be 1.
+#> Inverse logic applied: values below threshold will be 1.
print(df_inverse_cutoff)
#> Simple feature collection with 780 features and 5 fields
#> Geometry type: POLYGON
@@ -192,38 +271,6 @@ Examples#> 9 ((116 -50, 118 -50, 118 -48, 116 -48, 116 -50)) 1 0 0 1 0
#> 10 ((118 -50, 120 -50, 120 -48, 118 -48, 118 -50)) 0 1 0 1 0
#> # ℹ 770 more rows
-
-# Example 4: Named cutoffs with inverse logic
-df_named_inverse <- splnr_apply_cutoffs(
- dat_species_prob,
- Cutoffs = c("Spp1" = 0.7, "Spp2" = 0.3),
- inverse = TRUE
-)
-#> Applying named cutoffs to specific feature columns.
-#> Applying cutoff 0.7 to column 'Spp1'.
-#> Inverse logic applied for column 'Spp1': values below cutoff will be 1.
-#> Applying cutoff 0.3 to column 'Spp2'.
-#> Inverse logic applied for column 'Spp2': values below cutoff will be 1.
-print(df_named_inverse)
-#> Simple feature collection with 780 features and 5 fields
-#> Geometry type: POLYGON
-#> Dimension: XY
-#> Bounding box: xmin: 100 ymin: -50 xmax: 160 ymax: 2
-#> Geodetic CRS: WGS 84
-#> # A tibble: 780 × 6
-#> geometry Spp1 Spp2 Spp3 Spp4 Spp5
-#> <POLYGON [°]> <dbl> <dbl> <dbl> <dbl> <dbl>
-#> 1 ((100 -50, 102 -50, 102 -48, 100 -48, 100… 1 1 0.0969 0.435 0.0418
-#> 2 ((102 -50, 104 -50, 104 -48, 102 -48, 102… 1 0 0.504 0.503 0.360
-#> 3 ((104 -50, 106 -50, 106 -48, 104 -48, 104… 1 0 0.285 0.755 0.653
-#> 4 ((106 -50, 108 -50, 108 -48, 106 -48, 106… 1 0 0.564 0.503 0.529
-#> 5 ((108 -50, 110 -50, 110 -48, 108 -48, 108… 1 0 0.150 0.863 0.753
-#> 6 ((110 -50, 112 -50, 112 -48, 110 -48, 110… 0 0 0.807 0.458 0.374
-#> 7 ((112 -50, 114 -50, 114 -48, 112 -48, 112… 1 0 0.00963 0.102 0.114
-#> 8 ((114 -50, 116 -50, 116 -48, 114 -48, 114… 1 1 0.481 0.231 0.764
-#> 9 ((116 -50, 118 -50, 118 -48, 116 -48, 116… 1 0 0.552 0.00978 0.552
-#> 10 ((118 -50, 120 -50, 120 -48, 118 -48, 118… 1 0 0.695 0.00687 0.815
-#> # ℹ 770 more rows