R 冲积图中的群冲积层

Group alluvia in the R alluvial diagram

在冲积包中,是否可以合并那些具有相同源节点和目标节点的冲积层?例如下图中的两个暗冲积层,都经过 AB 和 3.

编辑:这是一个使用泰坦尼克号数据集的示例,它显示了相同的行为:

# 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)

它看起来像 ggalluvial 包作为 geom_flow 在每个类别中断时重置。这可能是你想要的更多。例如

# 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()