-
Notifications
You must be signed in to change notification settings - Fork 26
/
Copy pathREADME.Rmd
101 lines (65 loc) · 2.73 KB
/
README.Rmd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
---
output:
github_document:
html_preview: false
bibliography: vignettes/alluvial.bib
editor_options:
chunk_output_type: console
---
```{r setup, include=FALSE, cache=FALSE}
library(alluvial)
library(dplyr)
knitr::opts_chunk$set(
fig.width=8,
fig.height=6,
fig.path = "tools/"
)
knitr::render_markdown(strict=FALSE)
```
# R package for drawing alluvial diagrams
<!-- badges: start -->
[![R-CMD-check](https://github.com/mbojan/alluvial/workflows/R-CMD-check/badge.svg)](https://github.com/mbojan/alluvial/actions)
[![rstudio mirror downloads](http://cranlogs.r-pkg.org/badges/alluvial?color=2ED968)](http://cranlogs.r-pkg.org/)
[![cran version](http://www.r-pkg.org/badges/version/alluvial)](https://cran.r-project.org/package=alluvial)
<!-- badges: end -->
What are alluvial diagrams? See for example:
* [Wikipedia](http://en.wikipedia.org/wiki/Alluvial_diagram)
* My [blog post](http://bc.bojanorama.pl/2014/03/alluvial-diagrams) showing-off this package
* Some discussion on [CrossValidated](http://stats.stackexchange.com/questions/12029/is-it-possible-to-create-parallel-sets-plot-using-r)
This package use base R **graphics** [@r-graphics] package. For Grammar of Graphics implementation see [**ggalluvial**](https://github.com/corybrunson/ggalluvial) [@r-ggalluvial;@ggalluvial-article].
## Examples
Alluvial diagram of `datasets::Titanic` data made with `alluvial()`. Notice how each category block becomes a stacked barchart showing relative frequency of survivors.
```{r alluvial}
tit <- tibble::as_tibble(Titanic)
tit %>% head() %>% knitr::kable()
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,
blocks=FALSE
)
```
Alluvial diagram for multiple time series / cross-sectional data based on `alluvial::Refugees` data made with `alluvial_ts()`.
```{r alluvial_ts}
Refugees %>% head() %>% knitr::kable()
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")
```
## Installation
Install stable version from CRAN using
```{r, eval=FALSE}
install.packages("alluvial")
```
or development version from GitHub using `remotes::install_github()`:
```{r, eval=FALSE}
remotes::install_github("mbojan/alluvial", build_vignettes=TRUE)
```
## References