3

In the alluvial package, is it possible to combine those alluvia that have the same source and target nodes? For example the two dark alluvia in the image below, that both go through AB and 3.

enter image description here

Edit: Here is an example using the Titanic dataset, which shows the same behaviour:

# Titanic data
tit <- as.data.frame(Titanic)
tit3d <- aggregate( Freq ~ Class + Sex + Survived, data=tit, sum)
ord <- list(NULL, with(tit3d, order(Sex, Survived)), NULL)
alluvial(tit3d[,1:3], freq=tit3d$Freq, alpha=1, xw=0.2,
         col=ifelse( tit3d$Survived == "No", "red", "gray"),
         layer = tit3d$Sex != "Female",
         border="white", ordering=ord)
Cos
  • 1,649
  • 1
  • 27
  • 50
  • When asking for help, you should include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions – MrFlick Jul 16 '18 at 14:15
  • I expected the result to be a configuration flag or something similar. I'll add an example. – Cos Jul 16 '18 at 15:17

1 Answers1

2

It looks like the ggalluvial package as a geom_flow which resets at each category break. That might be more of what you want. For example

# reshape data
library(dplyr)
library(tidyr)
dd <- tit3d %>% mutate(id=1:n(), sc=Survived) %>% 
  gather("category", "value", -c(id, Freq, sc))

# draw plot
ggplot(dd, aes(x=category, stratum=value, alluvium = id, 
               label=value))+ 
 geom_flow(aes(fill=sc))  + 
 geom_stratum(alpha = .5) + geom_text(stat = "stratum", size = 3) + 
  theme_minimal()

enter image description here

MrFlick
  • 195,160
  • 17
  • 277
  • 295