stat_events: Extreme events.

Description Usage Arguments Author(s) Examples

Description

stat_events computes a data frame to adequatly draw areas corresponding to extreme events in a time series.

Usage

1
2
3
stat_events(mapping = NULL, data = NULL, geom = "ribbon",
  position = "identity", na.rm = FALSE, show.legend = NA,
  inherit.aes = TRUE, ...)

Arguments

mapping

Aesthetic mapping created by aes or aes.

data

Dataset to use.

geom

Geometry.

position

Position.

na.rm

Logical value to remove missing values.

show.legend

Show legend.

inherit.aes

Inherit aesthetics.

...

Additional arguments passed to layer.

Author(s)

Erick A. Chacon-Montalvan

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# Obtain a zero-mean time series
library(ggplot2)
economics <- transform(economics,
  unemploy_zero = 2 * (unemploy - mean(unemploy)) / sd(unemploy))

# Plot time series with appropiate shade for negative and positive values
ggplot(economics, aes(date, unemploy_zero)) +
  geom_line() +
  geom_point(color = 2, alpha = 0.3) +
  stat_events(alpha = 0.3)

# Plot time series with appropiate shade for a given threshold
ggplot(economics, aes(date, unemploy_zero)) +
  geom_line() +
  geom_point(color = 2, alpha = 0.3) +
  stat_events(threshold = 0.5, alpha = 0.3)

# Plot time series with appropiate shade for a given threshold
ggplot(economics, aes(date, unemploy_zero)) +
  geom_line() +
  stat_events(aes(event = I(1 * (unemploy_zero > 1)), fill = "positive peak"),
              threshold = 1, alpha = 0.3) +
  stat_events(aes(event = I(1 * (unemploy_zero < -1)), fill = "negative peak"),
              threshold = -1, alpha = 0.3)

ErickChacon/mbsi documentation built on Aug. 1, 2019, 4:47 p.m.