stat_steamgraph: Plot multiple time series as a steamgraph

Description Usage Arguments Aesthetics Cosmetic Tips Examples

View source: R/stat_steamgraph.R

Description

Plot multiple time series as a steamgraph

Usage

1
2
stat_steamgraph(mapping = NULL, data = NULL, show.legend = NA,
  inherit.aes = TRUE, na.rm = T, ...)

Arguments

mapping

mapping

data

data

show.legend

logical

inherit.aes

logical

na.rm

logical

...

other functions

Plots geom_ribbon for each time series and stacks them one on top of the other. It's a more aesthetically appealing version of a stacked area chart. The groups with the most variance are placed on the outside, and the groups with the least variance are placed on the inside.

Aesthetics

geom_steamgraph needs x, y, group, fill.

Cosmetic Tips

The minimalist look can be achieved by appending the following chunk of code to the example output object: + xlab(NULL) + ylab(NULL) + theme( axis.text = element_blank(), axis.ticks = element_blank(), legend.position = 'none', strip.background = element_blank(), # strip.text = element_blank(), # useful if only one year of data plot.background = element_blank(), panel.background = element_blank(), panel.border = element_blank(), panel.grid = element_blank(), panel.border = element_blank() ) + coord_fixed( 0.2 * diff(range(df$Time)) / diff(range(df$Signal)))

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
{
library(ggplot2)
set.seed(10)
df = data.frame(
Time=1:1000,
Signal=abs(c(cumsum(rnorm(1000, 0, 3)),
    cumsum(rnorm(1000, 0, 4)), cumsum(rnorm(1000, 0, 1)),
     cumsum(rnorm(1000, 0, 2)))),
Variable = c(rep('a', 1000), rep('b', 1000), rep('c',
    1000), rep('d', 1000)),
VariableLabel = c(rep('Class A', 1000), rep('Class B',
    1000), rep('Class C', 1000), rep('Class D', 1000))
)

ggplot(df, aes(x = Time, y = Signal, group = Variable, fill = VariableLabel)) +
  stat_steamgraph()}

Example output

Loading required package: ggplot2

ggTimeSeries documentation built on Jan. 23, 2022, 5:07 p.m.