在冲积层中,是否可以合并具有相同源节点和目标节点的那些冲积层?例如,下图中的两个暗色别针藻都通过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()