histogram_plot: Produce a histogram of elements by station.

View source: R/histogram_plot.R

histogram_plotR Documentation

Produce a histogram of elements by station.

Description

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

Usage

histogram_plot(
  data,
  date_time,
  elements,
  station = NULL,
  facet_by = c("stations", "elements", "stations-elements", "elements-stations",
    "none"),
  position = c("identity", "dodge", "dodge2", "stack", "fill", "layer"),
  colour_bank = NULL,
  na_rm = FALSE,
  orientation = NA,
  show_legend = NA,
  width = NULL,
  facet_nrow = NULL,
  facet_ncol = NULL,
  title = "Histogram 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. Histogram 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".

position

character(1) Position adjustment.

colour_bank

character A string denoting colour values if position == "layer". By default, colours from ggplot2::luv_colours are used.

na_rm

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

orientation

The orientation of the layer. The default (NA) automatically determines the orientation from the aesthetic mapping. In the rare event that this fails it can be given explicitly by setting orientation to either "x" or "y".

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.

width

Bar width. By default, set to 90% of the resolution of the data.

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.

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

data("daily_niger")

# Create a histogram plot with facets by both elements and stations
data(daily_niger)
daily_niger_1 <- daily_niger %>% dplyr::filter(year < 1950)
histogram_plot(data = daily_niger_1, date_time = "date",
               facet_by = "stations-elements",
               elements = c("tmax", "tmin"), station = "station_name")
               
# Can make additional changes to the plot since the returned object is a \code{ggplot2} object
# for example, to edit the colours in the plot:
require(ggplot2)
t1 <- histogram_plot(data = daily_niger_1, date_time = "date", elements = c("rain", "tmax"),
                     position = "dodge", station = "station_name")
t1 + ggplot2::scale_colour_discrete(type = c("red", "black"))

# Can additionally layer elements in a single plot
histogram_plot(data = daily_niger_1, date_time = "date", position = "layer",
               facet_by = "stations",
               elements = c("tmax", "tmin"), station = "station_name",
               colour_bank = c("purple", "orange"))

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