R/fPlot_InterannualTimeSeries_16panel_InitialQC.R

Defines functions fPlot_InterannualTimeSeries_16panel_InitialQC

Documented in fPlot_InterannualTimeSeries_16panel_InitialQC

#' This function takes a dataframe of timestamped environmental/flux variables and plots them as individual facets in a 16-panel plot.
#' Data are plotted as a continuous time series for a single 365-day year (with individual years of record overlaid as different color levels)


#' @export
#' @title 16-panel composite plot for initial data QC (interannual time series)
#' @param site.info a named vector containing the following variables: site, db, info, country, lat, long, MAT, MAP, IGBP
#' @param dat a dataframe containing timestamped variable columns
#' @param DOY_col a character object specifying the day of year column (which is a numeric vector 1-366)
#' @param year_col a character object specifying the year column
#'
#' @details A bit more information about the 'site.info' dataframe columns:
#' \describe{
#' \item{site}{character object denoting the abbreviated site name (e.g. 'US-NR1')}
#' \item{db}{character object denoting the abbreviated database name (e.g. 'FLX')}
#' \item{info}{character string denoting the full site name (e.g. 'Niwot Ridge, CO')}
#' \item{country}{character object denoting the country of origin for site (e.g. 'United States')}
#' \item{lat}{numeric object denoting the site latitude}
#' \item{long}{numeric object denoting the site longitude}
#' \item{MAT}{numeric object denoting the site mean annual temperature (deg C)}
#' \item{MAP}{numeric object denoting the site mean annual precipitation (mm)}
#' \item{IGBP}{character object denoting the International Geosphere-Biosphere Programme land classification (e.g. 'ENF')}
#' }
#' @importFrom ggplot2 ggplot aes geom_line geom_vline scale_x_continuous scale_y_continuous ggtitle theme element_text element_blank element_line


fPlot_InterannualTimeSeries_16panel_InitialQC <- function(site.info, dat, DOY_col, year_col){

  # plot time series of: k_NEE
  f.NEE_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_NEE", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("NEE",paste("(µmol ",CO[2]," ",m^-2," ",s^-1,")")))) +
    ggtitle("Net Ecosystem Exchange")

  # plot time series of: k_LE
  f.LE_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_LE", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("LE", paste("(W ",m^-2,")")))) +
    ggtitle("Latent Heat Flux")

  # plot time series of: k_H
  f.H_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_H", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("H", paste("(W ",m^-2,")")))) +
    ggtitle("Sensible Heat Flux")

  # plot time series of: k_SW_in
  f.SW_in_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_SW_in", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("SW_in", paste("(W ",m^-2,")")))) +
    ggtitle("SW radiation, incoming")

  # plot time series of: k_SW_out
  f.SW_out_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_SW_out", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("SW_out", paste("(W ",m^-2,")")))) +
    ggtitle("SW radiation, outgoing")

  # plot time series of: k_LW_in
  f.LW_in_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_LW_in", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("LW_in", paste("(W ",m^-2,")")))) +
    ggtitle("LW radiation, incoming")

  # plot time series of: k_LW_out
  f.LW_out_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_LW_out", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("LW_out", paste("(W ",m^-2,")")))) +
    ggtitle("LW radiation, outgoing")

  # plot time series of: k_albedo
  f.albedo_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_albedo", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("Albedo")), limits = c(0,1)) +
    ggtitle("Albedo")

  # plot time series of: k_Rnet
  f.Rnet_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_Rnet", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("Rnet", paste("(W ",m^-2,")")))) +
    ggtitle("Net radiation")

  # plot time series of: k_Tair
  f.Tair_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_Tair", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("Tair", paste("(\u00B0C)")))) +
    ggtitle("Air temperature")

  # plot time series of: k_Tsoil
  f.Tsoil_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_Tsoil", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("Tsoil", paste("(\u00B0C)")))) +
    ggtitle("Soil temperature")

  # plot time series of: k_SWC
  f.SWC_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_SWC", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("SWC", paste("(%)")))) +
    ggtitle("Soil water content")

  # plot time series of: k_RH
  f.RH_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_RH", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("RH", paste("(%)")))) +
    ggtitle("Relative humidity")

  # plot time series of: k_VPD
  f.VPD_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_VPD", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("VPD", paste("(hPa)")))) +
    ggtitle("Vapor pressure deficit")

  # plot time series of: k_ustar
  f.ustar_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_ustar", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("U*", paste("(",m^-2,")")))) +
    ggtitle("Friction velocity")

  #plot time series of: k_PPFD
  f.PPFD_interann <- fPlot_GroupedLine_Single(dat = dat, xcol = DOY_col, ycol = "k_PPFD", group = year_col) +
    scale_x_continuous(name = "DoY", breaks = seq(0,365, by = 60)) +
    scale_y_continuous(name=expression(atop("PPFD",paste("(µmol photon ",m^-2," ",s^-1,")")))) +
    ggtitle("Photosynthetic photon flux density")

  # Create faceted plot of all subplots
  f.composite_interann <- f.NEE_interann + f.LE_interann + f.H_interann + f.Rnet_interann + f.SW_in_interann + f.SW_out_interann + f.LW_in_interann + f.LW_out_interann + f.albedo_interann +
    f.Tair_interann + f.Tsoil_interann + f.SWC_interann + f.RH_interann + f.VPD_interann + f.ustar_interann + f.PPFD_interann + plot_layout(ncol=4)


  fig_interann <- patchwork::wrap_elements(f.composite_interann)

  # Add a title to your plot that includes all of the site metadata
  fig_interann <- fAddSiteMeta2Plot(fig_interann, site = site.info$site,
                                db = site.info$db,
                                longname = site.info$info,
                                country = site.info$country,
                                lat = site.info$lat,
                                long = site.info$long,
                                MAT = site.info$MAT,
                                MAP = site.info$MAP,
                                IGBP = site.info$IGBP)

  newlist <- list(fig_interann, f.NEE_interann, f.LE_interann, f.H_interann, f.Rnet_interann, f.SW_in_interann, f.SW_out_interann, f.LW_in_interann, f.LW_out_interann, f.albedo_interann,
                  f.Tair_interann, f.Tsoil_interann, f.SWC_interann, f.RH_interann, f.VPD_interann, f.ustar_interann, f.PPFD_interann)
  names(newlist) <- c("fig_interann", "f.NEE_interann", "f.LE_interann", "f.H_interann", "f.Rnet_interann", "f.SW_in_interann", "f.SW_out_interann", "f.LW_in_interann", "f.LW_out_interann", "f.albedo_interann",
                      "f.Tair_interann", "f.Tsoil_interann", "f.SWC_interann", "f.RH_interann", "f.VPD_interann", "f.ustar_interann", "f.PPFD_interann")
  return(newlist)
}
ksmiff33/FluxSynthU documentation built on Dec. 15, 2020, 10:29 p.m.