Skip to content
This repository was archived by the owner on May 10, 2022. It is now read-only.

Latest commit

 

History

History
56 lines (46 loc) · 1.49 KB

alluvial_plot.md

File metadata and controls

56 lines (46 loc) · 1.49 KB

Alluvial

Adam Gruer 23/11/2018

install.packages("ggalluvial")
library(ggplot2)
library(ggalluvial)
library(gganimate)

ICEBERG!!!

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

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)