Make DenseLines Heatmaps with 'ggplot2'

Visualise overlapping time series lines as a heatmap of line density. Provides a 'ggplot2' statistic implementing the DenseLines algorithm, which "normalizes time series by the arc length to compute accurate densities" (Moritz and Fisher, 2018) .


gglinedensity

The goal of gglinedensity is to bring the DenseLines algorithm to R via ggplot2, providing a “derived density visualisation (that) allows users both to see the aggregate trends of multiple (time) series and to identify anomalous extrema” (Moritz and Fisher, 2018).

Installation

You can install gglinedensity like so:

install.packages("gglinedensity")

You can install the development version of gglinedensity like so:

# install.packages("pak")
pak::pak("hrryt/gglinedensity")

Example

This is a basic example which shows you how to create a DenseLines heatmap:

library(ggplot2)
library(gglinedensity)

ggplot(txhousing, aes(date, median, group = city)) +
  stat_line_density(bins = 50, drop = FALSE, na.rm = TRUE)

You can also calculate the number of paths crossing a given bin, without using the DenseLines algorithm:

ggplot(dplyr::storms, aes(long, lat, group = name)) +
    borders(colour = NA, fill = "grey50") +
    stat_path_density(geom = "tile", binwidth = 1.25, na.rm = TRUE) +
    borders() +
    xlim(-180, 0) +
    ylim(-40, 80) +
    coord_sf(
        crs = sf::st_crs(5070),
        default_crs = sf::st_crs(4326),
        xlim = c(-120, -30), ylim = c(0, 70)
    ) +
    theme(panel.background = element_rect(fill = "grey10"))

Reference manual

It appears you don't have a PDF plugin for this browser. You can click here to download the reference manual.

install.packages("gglinedensity")

0.2.0 by Harry Thompson, a year ago


https://github.com/hrryt/gglinedensity, https://hrryt.github.io/gglinedensity/


Report a bug at https://github.com/hrryt/gglinedensity/issues


Browse source code at https://github.com/cran/gglinedensity


Authors: Harry Thompson [cre, aut, cph] , Dominik Moritz [aut] (Rust original , <https://github.com/domoritz/line-density-rust>) , The authors of the dependency Rust crates [ctb] (see inst/AUTHORS file for details) , Hiroaki Yutani [ctb] , Scripts where noted , <https://yutannihilation.github.io/string2path>)


Documentation:   PDF Manual  


GPL (>= 3) license


Imports cli, ggplot2, lifecycle, rlang, scales, vctrs, vdiffr

Suggests testthat

System requirements: Cargo (Rust's package manager), rustc >= 1.70.0


See at CRAN