Chapter 7 Trajectory graphs and trend maps
Now that we have calculated values for the trends and trajectories, bbsBayes also includes functions to plot and map the values.
# load the trend and indices objects for Scarlet Tanager load("Scarlet_Tanager_trends_indices.RData")
7.1 Graphing the trajectories (annual indices)
plot_indices() function produces a list of ggplot figures that can be combined into a single pdf file:
# Not run = plot_indices(indices = indices, tp species = "Scarlet Tanager") pdf(file = "Scarlet Tanager Trajectories.pdf") print(tp) dev.off()
Or, we can print plots to individual devices:
= plot_indices(indices = indices, tp species = "Scarlet Tanager") print(tp[])
plot_indices() also allows the user to add points to show the observed mean counts as well as stacked dots to indicate the number of observations in each year.
= plot_indices(indices = indices, tp2 species = paste("Scarlet Tanager","Full"), add_observed_means = TRUE, add_number_routes = TRUE)
And we can compare these indices plots with those generated using only the smooths.
= plot_indices(indices = indices_smooth, tp3 species = paste("Scarlet Tanager","Smooth"), add_observed_means = TRUE, add_number_routes = TRUE)
Using the patchwork library, we can show these plots side-by-side:
7.2 Adding elements to indices plots
The output of the
plot_indices() function is a list of ggplot objects, it is relatively easy to add components to the basic plot.
Here, we’ll use the first plot (continental trajectory) from the full population trajectory version above
tp2[] as the base plot, and we’ll add the smooth population trajectory information to the graph in a different colour.
First, extract the smooth population trajectory information in a dataframe.
library(tidyverse) <- indices_smooth$data_summary %>% continental_smooth filter(Region == "Continental")
Then we overlap the original plot with a new line and uncertainty ribbon.
<- tp2[] + overlay_plot geom_ribbon(data = continental_smooth,inherit.aes = FALSE, aes(x = Year,ymax = Index_q_0.25,ymin = Index_q_0.975), alpha = 0.2, fill = "darkgreen")+ geom_line(data = continental_smooth, inherit.aes = FALSE, aes(x = Year,y = Index), colour = "darkgreen") print(overlay_plot)
7.3 Mapping the trends
The trends can be mapped to produce strata maps coloured by species population trends.
= generate_map(trends_smooth, mp select = TRUE, stratify_by = "bbs_cws", species = "Scarlet Tanager Smooth") print(mp)
7.4 Geofacet Trajectories
For stratifications that can be compiled by political regions (i.e.,
state), the function
geofacet_plot will generate a ggplot object that plots the state and province level population trajectories in facets arranged in an approximately geographic arrangement. These plots offer a concise, range-wide summary of a species’ population trajectory.
<- geofacet_plot(indices_list = indices_smooth, gf select = TRUE, stratify_by = "bbs_cws", multiple = TRUE, trends = trends_smooth, slope = F, species = "Scarlet Tanager Smooth") print(gf)