stat_horizon: Plot a time series as a horizon plot

Description Usage Arguments Aesthetics Other parameters Cosmetic Tips Also See Examples

View source: R/stat_horizon.R

Description

Plot a time series as a horizon plot

Usage

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

Arguments

mapping

mapping

data

dataframe

show.legend

logical

inherit.aes

logical

na.rm

logical

bandwidth

bandwith

...

other functions

A horizon plot breaks the Y dimension down using colours. This is useful when visualising y values spanning a vast range and / or trying to highlight outliers without losing context of the rest of the data. Horizon plots are best viewed in an apsect ratio of very low vertical length.

Aesthetics

x, y, fill. Fill argument is overridden internally but is required for ggplot to assign a colour / fill scale.

Other parameters

bandwidth, to dictate the span of a band.

Cosmetic Tips

The minimalist look can be achieved by appending the following chunk of code to the output object: + xlab(NULL) + ylab(NULL) + scale_fill_continuous(low = 'green', high = 'red') + 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.border = element_blank(), panel.background = element_blank(), panel.grid = element_blank(), panel.border = element_blank() )

Also See

ggplot_horizon, a more polished but less flexible alternative.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
{
library(ggplot2)
ggplot(data.frame(x = 1:89, y = as.numeric(unlist(austres))), aes(x =x, y = y, fill = y) )+
   stat_horizon() +
   scale_fill_continuous(low = 'white', high = 'red')

set.seed(10)
ggplot(data.frame(x = 1:1000, y = cumsum(rnorm(1000))), aes(x =x, y = y, fill = y) )+
   stat_horizon() +
   scale_fill_continuous(low = 'white', high = 'red')}

Example output

Loading required package: ggplot2

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