Home > OS >  `ggalluvial`: `geom_flow` fill color from destination stratum
`ggalluvial`: `geom_flow` fill color from destination stratum

Time:02-19

I have the following example:

library(tidyverse)
library(ggalluvial)
data <- tibble(id = paste0("S", 1:20), 
       class_1 = c(rep("A", 10), rep("B", 10)),
       class_2 = c(rep("A", 8), rep("B", 8), rep("A", 4)))
data_pvt <- data %>%
    pivot_longer(starts_with("class"), names_to = "class_type", values_to = "class_label") %>%
    mutate(class_type = factor(class_type),
           class_label = factor(class_label))
ggplot(data_pvt, aes(x = fct_rev(class_type), stratum = class_label, alluvium = id,
                     label = class_label))  
    geom_flow(aes(fill = class_label), stat = "alluvium", 
              lode.guidance = "frontback")  
    geom_stratum(aes(fill = class_label))  
    scale_x_discrete(expand = c(0.1, 0))  
    labs(x = "Class system", y = "n")  
    coord_flip()  
    theme_minimal()

Created on 2022-02-18 by the enter image description here

  • Related