alluvial R package

repository·master·Indexed 40 days ago

https://github.com/mbojan/alluvial

An R package for drawing alluvial diagrams using base R graphics. It provides the alluvial() function for categorical data visualization and the alluvial_ts() function for analyzing multiple time-series or cross-sectional data.

Tokens
612
Snippets
3
Records
3
Agent score
0%

What's inside alluvial

  1. Install the alluvial R package

    master

    You can install the stable version of alluvial from CRAN or the development version from GitHub.

    From CRAN:

    install.packages("alluvial")

    From GitHub (Development version):

    remotes::install_github("mbojan/alluvial", build_vignettes=TRUE)
    install.packages("alluvial")
  2. Create an alluvial diagram with alluvial()

    master

    The alluvial() function is used to create alluvial diagrams from categorical data. It uses base R graphics.

    Note: The blocks argument is deprecated. Use the strata argument instead. The strata argument accepts:

    • TRUE (or "box"): Displays categories as blocks.
    • FALSE (or "stripes"): Displays categories as stripes.
    • strata_bookends(): For bookend styles.

    Example using datasets::Titanic data:

    tit <- tibble::as_tibble(Titanic)
    
    alluvial(
        select(tit, Survived, Sex, Age, Class),
        freq=tit$n,
        col = ifelse(tit$Survived == "Yes", "orange", "grey"),
        border = ifelse(tit$Survived == "Yes", "orange", "grey"),
        layer = tit$Survived != "Yes",
        alpha = 0.8,
        strata = FALSE
      )
  3. Create time series alluvial diagrams with alluvial_ts()

    master

    The alluvial_ts() function is designed for multiple time series or cross-sectional data, such as tracking refugee flows over several years.

    Example using alluvial::Refugees data:

    set.seed(39) # for nice colours
    cols <- hsv(h = sample(1:10/10), s = sample(3:12)/15, v = sample(3:12)/15)
    
    alluvial_ts(Refugees, wave = .3, ygap = 5, col = cols, plotdir = 'centred', alpha=.9,
                grid = TRUE, grid.lwd = 5, xmargin = 0.2, lab.cex = .7, xlab = '',
                ylab = '', border = NA, axis.cex = .8, leg.cex = .7,
                leg.col='white', 
                title = "UNHCR-recognised refugees\nTop 10 countries (2003-13)\n")