inventory_plot: Produce an inventory of available and missing data

View source: R/inventory_plot.R

inventory_plotR Documentation

Produce an inventory of available and missing data

Description

Returns an inventory plot using ggplot2 that displays whether a value is observed or missing for each element and station given. Takes a data frame as an input and the relevant columns to create the plot.

Usage

inventory_plot(
  data,
  date_time,
  elements,
  station = NULL,
  year = NULL,
  doy = NULL,
  year_doy_plot = FALSE,
  facet_by = NULL,
  facet_x_size = 7,
  facet_y_size = 11,
  title = "Inventory Plot",
  plot_title_size = NULL,
  plot_title_hjust = 0.5,
  x_title = NULL,
  y_title = NULL,
  x_scale_from = NULL,
  x_scale_to = NULL,
  x_scale_by = NULL,
  y_date_format = NULL,
  y_date_scale_by = NULL,
  y_date_scale_step = 1,
  facet_scales = "fixed",
  facet_dir = "h",
  facet_x_margin = ggplot2::margin(1, 0, 1, 0),
  facet_y_margin = ggplot2::margin(1, 0, 1, 0),
  facet_nrow = NULL,
  facet_ncol = NULL,
  missing_colour = "red",
  present_colour = "grey",
  missing_label = "Missing",
  present_label = "Present",
  display_rain_days = FALSE,
  rain = NULL,
  rain_cats = list(breaks = c(0, 0.85, Inf), labels = c("Dry", "Rain"), key_colours =
    c("tan3", "blue")),
  coord_flip = FALSE
)

Arguments

data

data.frame The data.frame to calculate from.

date_time

Date The name of the date column in data.

elements

character The name of the elements column in data to apply the function to.

station

character(1) The name of the station column in data, if the data are for multiple station.

year

character(1) The name of the year column in data. If NULL it will be created using lubridate::year(data[[date_time]]).

doy

character(1) The name of the day of the year (1-366) column in data. If doy is NULL then it can be calculated as yday_366(data[[date_time]]) if date_time is provided.

year_doy_plot

logical(1) Whether the day of year should be on the y-axis on the plot.

facet_by

character(1) Whether to facet by stations, elements, or both. Options are "stations", "elements", "station-elements", "elements-stations". In "station-elements", stations are given as rows and elements as columns. In "elements-stations", elements are given as rows and stations as columns.

facet_x_size

numeric(1) Text size for the facets on the x-axis in pts.

facet_y_size

numeric(1) Text size for the facets on the y-axis in pts.

title

character(1) The text for the title.

plot_title_size

numeric(1) Text size for the title in pts.

plot_title_hjust

numeric(1) Horizontal justification for title. Value between 0 and 1.

x_title

character(1) The text for the x-axis.

y_title

character(1) The text for the y-axis.

x_scale_from

integer(1) The year to display the inventory plot from.

x_scale_to

integer(1) The year to display the inventory plot to.

x_scale_by

integer(1) The difference, in years, to give the x tick marks between from and to.

y_date_format

TODO

y_date_scale_by

TODO

y_date_scale_step

TODO

facet_scales

character(1) Are scales shared across all facets (the default, "fixed"), or do they vary across rows ("free_x"), columns ("free_y"), or both rows and columns ("free")?

facet_dir

TODO

facet_x_margin

numeric(4) Margin width around the text for the x-facets.

facet_y_margin

numeric(4) Margin width around the text for the y-facets.

facet_nrow

integer(1) Number of rows for the facets if facet_by is one of "stations" or "elements". Only if facet_ncol is given.

facet_ncol

integer(1) Number of rows for the facets if facet_by is one of "stations" or "elements". Only if facet_nrow is given.

missing_colour

character(1) Colour to represent the missing values. Default "red".

present_colour

character(1) Colour to represent the observed values. Default "grey".

missing_label

character(1) Label to give in legend for missing values. Default "Missing".

present_label

character(1) Label to give in legend for observed values. Default "Present".

display_rain_days

logical(1) If rain parameter is not NULL, and rain is not an element in the elements parameter, whether to include dry and rainy days.

rain

character(1) The name of the rain column in data.

rain_cats

TODO

coord_flip

logical(1) Whether to switch the x and y axes.

labels

character If display_rain_days = TRUE, the labels in the key for dry and rainy days. By default, c("Dry", "Rain")

key_colours

character If display_rain_days = TRUE, the colours for dry and rainy days. By default, c("tan3", "blue"))

Value

A plot of type ggplot to the default plot device

Examples

# Create an inventory plot with two elements and by station.
data(daily_niger)
inventory_plot(data = daily_niger, station = "station_name", elements = c("tmax", "tmin"),
               date_time = "date")

# Create an inventory plot by year and day of year
inventory_plot(data = daily_niger, station = "station_name", elements = c("tmax", "tmin"),
               date_time = "date", year_doy_plot = TRUE)

# Can add in rainy/dry days into the plot
inventory_plot(data = daily_niger, station = "station_name", elements = c("tmax", "tmin"),
               date_time = "date", rain = "rain", display_rain_days = TRUE)

IDEMSInternational/cdms.products documentation built on July 7, 2023, 10:13 a.m.