【问题标题】:Group alluvia in the R alluvial diagramR冲积图中的组冲积层
【发布时间】:2018-07-16 13:24:13
【问题描述】:

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

编辑:这是一个使用 Titanic 数据集的示例,它显示了相同的行为:

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

【问题讨论】:

  • 寻求帮助时,您应该包含一个简单的reproducible example,其中包含可用于测试和验证可能解决方案的示例输入和所需输出
  • 我预计结果是配置标志或类似的东西。我将添加一个示例。

标签: r sankey-diagram dataflow-diagram


【解决方案1】:

它看起来像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()

【讨论】:

  • 这绝对是完美的。谢谢!
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2023-01-29
  • 2021-07-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2020-01-23
相关资源
最近更新 更多