PlotWeeklyClim {CSTools}R Documentation

Plots the observed weekly means and climatology of a timeseries data

Description

This function plots the observed weekly means and climatology of a timeseries data using ggplot package. It compares the weekly climatology in a specified period (reference period) to the observed conditions during the target period analyzed in the case study.

Usage

PlotWeeklyClim(
  data,
  first_date,
  ref_period,
  last_date = NULL,
  data_years = NULL,
  time_dim = "time",
  sdate_dim = "sdate",
  ylim = NULL,
  title = NULL,
  subtitle = NULL,
  ytitle = NULL,
  legend = TRUE,
  palette = "Blues",
  fileout = NULL,
  device = NULL,
  width = 8,
  height = 6,
  units = "in",
  dpi = 300
)

Arguments

data

A multidimensional array with named dimensions with at least sdate and time dimensions containing observed daily data. It can also be a dataframe with computed percentiles as input for ggplot. If it's a dataframe, it must contain the following column names: 'week', 'clim', 'p10', 'p90', 'p33', 'p66', 'week_mean', 'day' and 'data'.

first_date

The first date of the observed values of timeseries. It can be of class 'Date', 'POSIXct' or a character string in the format 'yyyy-mm-dd'. If parameter 'data_years' is not provided, it must be a date included in the reference period.

ref_period

A vector of numeric values indicating the years of the reference period. If parameter 'data_years' is not specified, it must be of the same length of dimension 'sdate_dim' of parameter 'data'.

last_date

Optional parameter indicating the last date of the target period of the daily timeseries. It can be of class 'Date', 'POSIXct' or a character string in the format 'yyyy-mm-dd'. If it is NULL, the last date of the daily timeseries will be set as the last date of 'data'. As the data is plotted by weeks, only full groups of 7 days will be plotted. If the last date of the timeseries is not a multiple of 7 days, the last week will not be plotted.

data_years

A vector of numeric values indicating the years of the data. It must be of the same length of dimension 'sdate_dim' of parameter 'data'. It is optional, if not specified, all the years will be used as the target period.

time_dim

A character string indicating the daily time dimension name. The default value is 'time'.

sdate_dim

A character string indicating the start year dimension name. The default value is 'sdate'.

ylim

A numeric vector of length two providing limits of the scale. Use NA to refer to the existing minimum or maximum. For more information, see 'ggplot2' documentation of 'scale_y_continuous' parameter.

title

The text for the top title of the plot. It is NULL by default.

subtitle

The text for the subtitle of the plot. It is NULL bu default.

ytitle

Character string to be drawn as y-axis title. It is NULL by default.

legend

A logical value indicating whether a legend should be included in the plot. If it is TRUE or NA, the legend will be included. If it is FALSE, the legend will not be included. It is TRUE by default.

palette

A palette name from the R Color Brewer’s package. The default value is 'Blues'.

fileout

A character string indicating the file name where to save the plot. If not specified (default) a graphics device will pop up.

device

A character string indicating the device to use. Can either be a device function (e.g. png), or one of "eps", "ps", "tex" (pictex), "pdf", "jpeg", "tiff", "png", "bmp", "svg" or "wmf" (windows only).

width

A numeric value of the plot width in units ("in", "cm", "mm", or "px"). It is set to 8 by default.

height

A numeric value of the plot height in units ("in", "cm", "mm", or "px"). It is set to 6 by default.

units

Units of the size of the device (file or window) to plot in. Inches (’in’) by default.

dpi

A numeric value of the plot resolution. It is set to 300 by default.

Value

A ggplot object containing the plot.

Examples

data <- array(rnorm(49*20*3, 274), dim = c(time = 49, sdate = 20, member = 3))
PlotWeeklyClim(data = data, first_date = '2002-08-09', 
              last_date = '2002-09-15', ref_period = 2010:2019, 
              data_years = 2000:2019, time_dim = 'time', sdate_dim = 'sdate',
              title = "Observed weekly means and climatology", 
              subtitle = "Target years: 2010 to 2019", 
              ytitle = paste0('tas', " (", "deg.C", ")"))


[Package CSTools version 5.2.0 Index]