This function calculates the mean y-value for each x-value. Should be used only when x is discrete. The resulting mean can be mapped to any aesthetic, specified with the output parameter.

stat_meanByHour(
  mapping = NULL,
  data = NULL,
  input = NULL,
  output = "y",
  geom = "bar",
  position = "identity",
  na.rm = TRUE,
  show.legend = NA,
  inherit.aes = TRUE,
  ...
)

Arguments

mapping

Set of aesthetic mappings created by aes(). If specified and inherit.aes = TRUE (the default), it is combined with the default mapping at the top level of the plot. You must supply mapping if there is no plot mapping.

data

The data to be displayed in this layer. There are three options: if NULL, the default, the data is inherited from the plot data. A data.frame or other object, will override the plot data. A function will be called with a single argument, the plot data. The return value must be a data.frame, and will be used as the layer data.

input

The value to find the mean of. If NULL, the default y value will be used.

output

"AQIColors", "mv4Colors", "scaqmd", "y"

geom

The geometic object to display the data

position

Position adjustment, either as a string, or the result of a call to a position adjustment function.

na.rm

remove NA values from data

show.legend

logical indicating whether this layer should be included in legends.

inherit.aes

if FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and the aesthetics and shouldn't inherit behaviour from the default plot specificatino, eg borders().

...

additional arguments passed on to layer(), such as aesthetics.

Examples

if (FALSE) {
library(AirMonitorPlots)

ggplot_pm25Timeseries(
  AirMonitor::NW_Megafires,
  startdate = 20150820,
  enddate = 20150831
) +
  geom_point(shape = "square", alpha = 0.05) +
  stat_meanByHour(geom = "line", color = "orange", size = 3)

ggplot_pm25Diurnal(
  AirMonitor::Carmel_Valley,
  startdate = 20160801,
  enddate = 20160810
) +
  geom_path(aes(group = day), color = "gray50") +
  stat_meanByHour(geom = "line", size = 4)
}