Skip to contents

This function creates raster maps of community-level in-situ diversification metrics across geographic space. It allows plotting a single diversification metric or, alternatively, generating three independent maps (Jetz-based, in-situ, and proportional diversification rates).

Usage

plot_insitu_diversification(
  insitu_diversification,
  coords,
  shapefile,
  variable = c("DR_jetz", "DR_insitu", "DR_prop"),
  color_palette = "SunsetDark",
  facet = FALSE
)

Arguments

insitu_diversification

A list generated by calc_insitu_diversification containing community-level in-situ diversification metrics. The object must include the elements jetz_comm_mean, insitu_comm_mean, and prop_comm_mean, each corresponding to a numeric vector with diversification values per site.

coords

A rectangular object (it can be a matrix, data.frame or tibble) containing two columns, one with longitude and another with latitude coordinates in this order.

shapefile

An sf object containing the geographic boundaries to be overlaid on the raster map (e.g., continents, biogeographic regions, or study area limits).

variable

character string indicating which diversification metric should be plotted when facet = FALSE. Must be one of "DR_jetz", "DR_insitu", or "DR_prop".

color_palette

character string specifying the color palette to be used for quantitative variables in rcartocolor::scale_fill_carto_c. Ignored for "DR_prop", which uses a fixed palette and scale. Default is "SunsetDark"

facet

Logical. If FALSE (default), a single raster map is produced for the selected variable. If TRUE, three maps (Jetz-based, in-situ, and proportional diversification rates) are generated and combined into a single layout, each with an independent color scale. Default is FALSE

Value

A ggplot2 object if facet = FALSE. When facet = TRUE, a patchwork object combining three ggplot2 objects is returned.

Author

Maria Gabriela Junqueira and Gabriel Nakamura

Examples

if (FALSE) { # \dontrun{

# Compute diversification metrics

akodon_diversification <- Herodotools::calc_insitu_diversification(W = akodon_pa_tree,
                                      tree = akodon_newick,
                                      ancestral.area = node_area,
                                      biogeo = biogeo_area,
                                      type = "equal.splits")
#Load data

site_xy <- akodon_sites |>
    dplyr::select(LONG, LAT)

coastline <- rnaturalearth::ne_coastline(returnclass = "sf")

coastline_crop <- sf::st_crop(coastline,
                          xmin = map_limits$x[1],
                          xmax = map_limits$x[2],
                          ymin = map_limits$y[1],
                          ymax = map_limits$y[2])

#Single map

plot_insitu_diversification(insitu_diversification = akodon_diversification,
                            coords = site_xy,
                            shapefile = coastline_crop,
                            variable = "DR_prop")

# Three maps with independent color scales

plot_insitu_diversification(insitu_diversification = akodon_diversification,
                            coords = site_xy,
                            shapefile = coastline_crop,
                            facet = TRUE)
} # }