This repository has been archived by the owner on May 10, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 23
/
alluvial_plot.Rmd
65 lines (51 loc) · 1.61 KB
/
alluvial_plot.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
---
title: "Alluvial"
author: "Adam Gruer"
date: "23/11/2018"
output:
github_document:
toc: true
---
```{r setup, include=FALSE}
knitr::opts_chunk$set(echo = TRUE)
```
```{r, eval=FALSE}
install.packages("ggalluvial")
```
```{r libraries}
library(ggplot2)
library(ggalluvial)
library(gganimate)
```
# ICEBERG!!!
## Static
```{r alluvial_static}
ggplot(data = to_lodes_form(as.data.frame(Titanic),
key = "Demographic",
axes = 1:3),
aes(x = Demographic, stratum = stratum, alluvium = alluvium,
y = Freq, label = stratum)) +
scale_x_discrete(expand = c(.05, .05)) +
geom_alluvium(aes(fill = Survived)) +
geom_stratum() +
geom_text(stat = "stratum") +
ggtitle("passengers on the maiden voyage of the Titanic",
"stratified by demographics and survival")
```
## Animated. HELP! SOS!
Wondering how I might animate the above chart. First attempt error:
> Error in mapply(FUN = f, ..., SIMPLIFY = FALSE) : zero-length inputs cannot be mixed with those of non-zero length
```{r alluvial_animated, eval=FALSE}
ggplot(data = to_lodes_form(as.data.frame(Titanic),
key = "Demographic",
axes = 1:3),
aes(x = Demographic, stratum = stratum, alluvium = alluvium,
y = Freq, label = stratum)) +
scale_x_discrete(expand = c(.05, .05)) +
geom_alluvium(aes(fill = Survived)) +
geom_stratum() +
geom_text(stat = "stratum") +
ggtitle("passengers on the maiden voyage of the Titanic",
"stratified by demographics and survival") +
transition_manual(Demographic)
```