【发布时间】:2017-08-04 15:21:31
【问题描述】:
目标
我的目标是使用 googleVis 包在 R 中制作多个 Sankey。输出应该类似于:
数据
我在 R 中创建了一些虚拟数据:
set.seed(1)
source <- sample(c("North","South","East","West"),100,replace=T)
mid <- sample(c("North ","South ","East ","West "),100,replace=T)
destination <- sample(c("North","South","East","West"),100,replace=T) # N.B. It is important to have a space after the second set of destinations to avoid a cycle
dummy <- rep(1,100) # For aggregation
dat <- data.frame(source,mid,destination,dummy)
aggdat <- aggregate(dummy~source+mid+destination,dat,sum)
到目前为止我已经尝试过什么
如果我只有一个源和目标,但没有中间点,我可以用 2 个变量构建一个 Sankey:
aggdat <- aggregate(dummy~source+destination,dat,sum)
library(googleVis)
p <- gvisSankey(aggdat,from="source",to="destination",weight="dummy")
plot(p)
代码产生这个:
问题
如何修改
p <- gvisSankey(aggdat,from="source",to="destination",weight="dummy")
也接受mid 变量?
【问题讨论】:
标签: r googlevis sankey-diagram