R/func_plot_norwest.R

Defines functions plot_norwest

Documented in plot_norwest

#' Plot temperature by site/PERMA_FID; plot faceted by year
#'
#' This function plots daily mean temperature for a user-specified PERMA_FID
#' within a user-specified data frame. If the PERMA_FID has multiple calendar
#' years of data, the plot is faceted by year.
#'
#' #' @param basin with data to be plotted, options are "Clearwater", "Salmon",
#' "SpoKoot", "MidSnake", "SnakeBear"
#' @param site PERMA_FID
#' @param parameter options are DailyMean, DailyMax, DailyMin, DailySD
#' @return ggplot2 line plot faceted by year; facet labels are OBSPRED_ID: SampleYear
#' @examples plot_norwest(Clearwater, 12163, DailyMean)
#' @export

plot_norwest <-function(basin, site, parameter) {

 data_for_plot <-subset(basin, PERMA_FID== site,
                        select = c(SampleDate, DailyMean, DailyMax, DailyMin,
                                   DailySD, OBSPRED_ID, SampleYear, GNIS_NAME))
 data_for_plot$monthday <-format(as.Date(data_for_plot$SampleDate, format = "%Y-%m-%d"), "%m-%d")
 data_for_plot$plotdate <-as.Date(paste("1904-", data_for_plot$monthday, sep = ""), format = "%Y-%m-%d")
 data_for_plot$facetlabel <-paste0(data_for_plot$OBSPRED_ID, ": ", data_for_plot$SampleYear)

 sitename <-unique(data_for_plot$GNIS_NAME)

  plot <-
    ggplot2::ggplot(data_for_plot, ggplot2::aes(x = plotdate, y = {{parameter}})) +
    ggplot2::geom_line() +
    ggplot2::facet_wrap(~facetlabel) +
    ggplot2::scale_x_date(date_labels = "%b") +
    ggplot2::xlab("Date") +
    ggplot2::ggtitle(paste0(sitename, " (PERMA_FID:", site, " )"))

  print(plot)

}
jjwill2/idtemp documentation built on Aug. 10, 2020, 12:44 a.m.