R/p_gam.R

Defines functions p_gam

Documented in p_gam

#' Generic function to print GAMs using mgcViz
#'
#' @param x a GAM object created by \code{\link[mgcv]{gam}}
#'
#' @return a `ggplot2` graph object of the GAM
#' @export p_gam
#'
#' @examples
#' # load necessary libraries
#' library("tidyverse")
#' library("mgcv")
#' library("mgcViz")
#' library("ChickpeaAscoDispersal")
#' 
#' # these data are automatically loaded
#' dat <- left_join(lesion_counts, summary_weather, by = c("site", "rep"))
#' 
#' mod1 <- gam(
#'   m_lesions ~ s(distance, k = 5),
#'   data = dat
#' )
#' 
#' print(p_gam(x = getViz(mod1)) +
#'         ggtitle("s(Distance)"),
#'       pages = 1)
#'       

p_gam <- function(x) {
   graphics::plot(x, allTerms = T) +
      mgcViz::l_points() +
      mgcViz::l_fitLine(linetype = 1)  +
      mgcViz::l_ciLine(linetype = 3) +
      mgcViz::l_ciBar() +
      mgcViz::l_rug()
}
adamhsparks/ChickpeaAscoDispersal documentation built on April 29, 2024, 12:32 p.m.