r - R冲积层图中的群冲积层

标签 r sankey-diagram dataflow-diagram

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

enter image description here

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

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

enter image description here

关于r - R冲积层图中的群冲积层,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51362907/

相关文章:

r - Ubuntu 上的 JRI fatal error

r - 将 R 中的每个条目的列转换为多行

将唯一列表中的 NA 替换为 R 中第二个列表中相同位置的 NA

r - 带有 mutate 的自定义函数不起作用

javascript - 如何从 json 文件分配桑基图 (D3) 中节点的 x 轴位置

r - 桑基网络手动换色

r - 如何从 data.frame 制作 googleVis 多个 Sankey?

java - UML 序列图 - 可视化数据验证