#' Plots results from biophysical indicator functions
#'
#' @description Plots results from the functions used to calculate biophysical indicators like: richness(), density(), ttrophic(), fish_biomass(), and fish_size().
#'
#' @param data dataframe generated by any of the following functions: richness(), density(), trophic(), fish_biomass(), and fish_size()
#'
#' @param error.bars A logical value indicating if error bars (1 SD) should be plotted.
#'
#' @export
#'
#' @author Villasenor-Derbez, J.C.
mpa_plot2 <- function(data, error.bars = F, y.lab = "Indicador"){
library(ggplot2)
library(dplyr)
library(tidyr)
colnames(data) <- c("Ano", "Zonificacion", "Sitio", "Transecto", "Indicador")
data <- data %>%
group_by(Ano, Zonificacion) %>%
mutate(SD = sd(Indicador, na.rm = T), Indicator = mean(Indicador, na.rm = T))
p <- ggplot(data, aes(x = Ano, y = Indicator, color = Zonificacion))+
geom_point()+
geom_line()+
theme_bw()+
scale_color_brewer(palette = "Set1")+
labs(x = "Año", y = y.lab)
if (error.bars){
p <- p +
geom_errorbar(aes(ymin = Indicator-SD, ymax = Indicator+SD), width = 0.2)
}
p
}
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.