R/mpa_plot4.R

#' Plot a turfeffect object for biophysical indicators
#'
#' @param model An object of class lm, generated by the turfeffect() function or extracted from the tibble output of the bio_results() function
#' @param y.lab A character that specifies the y.label
#'
#' @return an object og class ggplot2
#' @export
#'

mpa_plot4 <- function(model, y.lab = NULL) {

  library(ggplot2)
  library(dplyr)
  library(tidyr)

  p <- model$model %>%
    mutate(Ano = as.numeric(as.character(Ano))) %>%
    ggplot(aes(x = Ano, y = Indicador, color = Zona, fill = Zona)) +
    stat_summary(fun.data = mean_se, geom = "ribbon", alpha = 0.5) +
    stat_summary(geom = "point", fun.y = mean, color = "black", size = 2, alpha = 0.5) +
    stat_summary(geom = "line", fun.y = mean, color = "black", alpha = 0.5) +
    geom_jitter(height = 0, width = 0.1, size = 1) +
    scale_color_brewer(palette = "Set1", direction = -1) +
    scale_fill_brewer(palette = "Set1", direction = -1) +
    theme_bw() + labs(x = "Ano", y = y.lab)

  return(p)
}
turf-reserves/mpa.tools documentation built on June 1, 2019, 2:55 a.m.