Skip to contents

Plot the mean arrival age of species in an assemblage based in an ancestral area reconstruction across geographic space

Usage

plot_age_arrival(
  age_arrival_comm,
  coords,
  shapefile,
  color_palette = "SunsetDark"
)

Arguments

age_arrival_comm

A list of length two generated by calc_age_arrival containing community-level the mean arrival age of species in an assemblage based in an ancestral area reconstruction.

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).

color_palette

character string specifying the color palette to be used for quantitative variables in rcartocolor::scale_fill_carto_c.

Value

A ggplot2 object is returned.

Author

Maria Gabriela Junqueira and Gabriel Nakamura

Examples

if (FALSE) { # \dontrun{

# Compute diversification metrics

data("akodon_sites") # site in rows and species and coordinates in columns
data("akodon_newick") # phylogeny

# pre computed evoregion
load(file = system.file("extdata", "regions_results.RData", 
                        package = "Herodotools")) 
site_region <- regions$Cluster_Evoregions # evoregions

# subseting longitude and latitude in a separate dataframe
site_xy <- akodon_sites %>% 
  dplyr::select(LONG, LAT) 

# subsetting species presence in a separate dataframe
akodon_pa <- akodon_sites %>% 
  dplyr::select(-LONG, -LAT)

# joining classification with site coordinates
evoregion_df <- data.frame(
  site_xy, 
  site_region
)

# bioregion/ecoregion/evoregion of each site
biogeo_area <- data.frame(biogeo = chartr("12345", 
                                          "ABCDE", 
                                          evoregion_df$site_region)) 

# pre computed biogeobears model 
load(file = system.file("extdata", 
                        "resDEC_akodon.RData",
                        package = "Herodotools")) 

# subseting occurrence matrix keeping only species in the phylogenetic tree
spp_in_tree <- names(akodon_pa) %in% akodon_newick$tip.label
akodon_pa_tree <- akodon_pa[, spp_in_tree]


# getting the ancestral range area for each node 
node_area <- 
  Herodotools::get_node_range_BioGeoBEARS(
    resDEC,
    phyllip.file = here::here("inst", "extdata", "geo_area_akodon.data"),
    akodon_newick,
    max.range.size = 4 
  )

# calculating age arrival
akodon_age_comm <- 
  Herodotools::calc_age_arrival(W = akodon_pa_tree,
                                tree = akodon_newick,
                                ancestral.area = node_area,
                                biogeo = biogeo_area)


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

# defining map limits
map_limits <- list(
  x = c(-95, -30),
  y = c(-55, 12)
)

# cropping map keeping only Soutbh America
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])


# plotting mean age of arrival for each cell
plot_age_arrival(age_arrival_comm = akodon_age_comm,
                 coords = site_xy,
                 shapefile = coastline_crop)

} # }