A ggplot2 stat
function to wrangle data for geom_hourglass
.
Source: R/stat_hourglass.R
stat_hourglass.Rd
Splits mapped x
or y
aesthetic from a continuous datetime into
discrete date values on the mapped axis. The hour of day is mapped to
the opposite axis.
Usage
StatHourglass
stat_hourglass(
mapping = NULL,
data = NULL,
geom = "hourglass",
position = "identity",
show.legend = NA,
inherit.aes = TRUE,
hour_center = 0,
na.rm = FALSE,
...
)
Arguments
- mapping
Set of aesthetic mappings created by
ggplot2::aes()
. If specified andinherit.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. Thehourglass
stat
andgeom
requires either thex
axis or they
axis to be mapped. The mapped aesthetic will show the date of the variable, whereas the opposite axis will show the time of day.- data
The data to be displayed in this layer. If
NULL
, the default, the data is inherited from the plot data as specified in the call toggplot2::ggplot()
. Otherwise, adata.frame
, or other object, will override the plot data. All objects will be fortified to produce a data frame. Seeggplot2::fortify()
for which variables will be created. The data should contain a column with datetime values (e.g.,?POSIXct
)- geom
Can be used to overwrite the default connection between
stat_hourglass
and[geom_hourglass]
.- position
A position adjustment to use on the data for this layer. This can be used in various ways, including to prevent overplotting and improving the display. The
position
argument accepts the following:The result of calling a position function, such as
position_jitter()
. This method allows for passing extra arguments to the position.A string naming the position adjustment. To give the position as a string, strip the function name of the
position_
prefix. For example, to useposition_jitter()
, give the position as"jitter"
.For more information and other ways to specify the position, see the layer position documentation.
- show.legend
logical. Should this layer be included in the legends?
NA
, the default, includes if any aesthetics are mapped.FALSE
never includes, andTRUE
always includes. It can also be a named logical vector to finely select the aesthetics to display.- 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 aesthetics and shouldn't inherit behaviour from the default plot specification, e.g.borders()
.- hour_center
The hour at which the time of day is centred. Default is 0, meaning midnight. -12 centres around noon of the preceding day, +12 centres around noon of the next day.
- na.rm
If
FALSE
, the default, missing values are removed with a warning. IfTRUE
, missing values are silently removed.- ...
Arguments passed as extra
param
s toggplot2::layer()
Value
Returns a ggplot2::layer()
which can be added to a ggplot2::ggplot()