#' Plot the relative abundance at family level
#' @description Plot the relative abundance at family level in bar plot
#' @name relative_abundance_plot
#' @param x data frame for input. This data frame should have the following columns. time: time step of simulation;
#' variable: consumer ID or resource ID; value: consumer or resource abundance; type: R or X;
#' reatment: treatment name; replicate: replicate number; function_group: defined by consumer type.
#' @return ...
family_abundance_plot <- function(
x) {
x %>%
group_by(treatment, replicate, function_group) %>%
# Sum up biomass at family level
summarize(family_biomass = sum(value)) %>%
mutate(
family_biomass_sum = sum(family_biomass),
family_biomass_proportion = family_biomass / family_biomass_sum
) %>%
ggplot(aes(x = replicate, y = family_biomass_proportion, fill = function_group)) +
geom_bar(stat = "identity", position = "fill") +
facet_grid(. ~ treatment) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
theme_bw() +
guides(fill = guide_legend(title = "Family")) +
labs(x = "replicate", y = "relative abundancee")
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.