timeseries_plot: Produce a timeseries graph

View source: R/timeseries_plot.R

timeseries_plotR Documentation

Produce a timeseries graph

Description

Returns a timeseries plot using ggplot2 for each element and station given. Takes a data frame as an input and the relevant columns to create the plot.

Usage

timeseries_plot(
  data,
  date_time,
  elements,
  station = NULL,
  facet_by = c("stations", "elements", "stations-elements", "elements-stations",
    "none"),
  type = c("line", "bar"),
  add_points = FALSE,
  add_line_of_best_fit = FALSE,
  se = TRUE,
  add_path = FALSE,
  add_step = FALSE,
  na_rm = FALSE,
  show_legend = NA,
  title = "Timeseries Plot",
  x_title = NULL,
  y_title = NULL
)

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. Timeseries plots are calculated separately for each station.

facet_by

character(1) Whether to facet by stations, elements, both, or neither. Options are "stations", "elements", "station-elements", "elements-stations", or "none".

type

character(1) The type of plot, either "line" or line graphs or "bar" for bar graphs.

add_points

logical(1) If TRUE, points are added to the plot using "ggplot2::geom_point()".

add_line_of_best_fit

logical(1) If TRUE, points are added to the plot using "ggplot2::geom_smooth(method = "lm")".

se

logical(1) If TRUE, the standard error is are added to the line of best fit. Only works if add_line_of_best_fit = TRUE.

add_path

logical(1) If TRUE, paths are added to the plot using "ggplot2::geom_path()".

add_step

logical(1) If TRUE, steps are added to the plot using "ggplot2::geom_step()".

na_rm

logical(1) If FALSE, the default, missing values are removed with a warning. If TRUE, missing values are silently removed.

show_legend

logical(1) Should this layer be included in the legends? NA, the default, includes if any aesthetics are mapped. FALSE never includes, and TRUE always includes.

title

character(1) The text for the title.

x_title

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

y_title

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

Value

a ggplot object.

Examples

# Create a time series plot with two elements and facet by station.
data(daily_niger)
daily_niger_1 <- daily_niger %>% dplyr::filter(year < 1950)
timeseries_plot(data = daily_niger_1, date_time = "date", elements = c("tmax", "tmin"), 
                station = "station_name", facet_by = "stations")

# Can make additional changes to the plot since the returned object is a \code{ggplot2} object
# for example, to add colour-blind friendly colours instead of the default colours
require(ggplot2)
t1 <- timeseries_plot(data = daily_niger_1, date_time = "date", elements = c("tmax", "tmin"), 
                      station = "station_name", facet_by = "stations")
t1 + ggplot2::scale_colour_discrete(type = c("#E69F00", "#56B4E9"))

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