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