R/plot_exposure.R

Defines functions plot_exposure

Documented in plot_exposure

#' Plot exposure profile
#' 
#' @param object a data frame with exposure column
#' 
#' @return a plot of class \code{ggplot}
#' 
#' @export
#' 
plot_exposure <- function(object){
  
  col_exposure <- .index_col_exposure(object)
  col_exp_time <- c(col_exposure, match("time", colnames(object)))
  
  col_names <- colnames(object[,col_exposure])
  ls_exp <- lapply(col_exposure, function(i) object[,i])
  
  df <- data.frame(
    time = rep(object$time, length(col_names)),
    route = rep(col_names, each = nrow(object)),
    exposure = do.call("c",ls_exp)
  )

  plt <- ggplot(data = df) + 
    theme_classic() +
    geom_line(aes_string(x = 'time', y = 'exposure')) +
    facet_wrap(~route, scales = "free")
  
  return(plt)
}

Try the rbioacc package in your browser

Any scripts or data that you put into this service are public.

rbioacc documentation built on Sept. 21, 2023, 5:06 p.m.