Description Usage Arguments Author(s) Examples
stat_events
computes a data frame to adequatly draw areas
corresponding to extreme events in a time series.
1 2 3 |
mapping |
Aesthetic mapping created by |
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 |
Erick A. Chacon-Montalvan
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)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.