我正在尝试使用Sankey图在R中可视化我的数据流。
我发现这篇博客文章链接到一个生成Sankey图的R脚本;不幸的是,它相当原始且有些受限(请参见下面的示例代码和数据)。
是否有人知道其他脚本或甚至是更完善的包?我的最终目标是通过图表组件的相对大小来可视化数据流和百分比,就像这些Sankey图的示例一样。
我在r-help列表上发布了一个类似的问题,但两周过去了没有任何回应,所以我在stackoverflow上试试运气。
谢谢, Eric
PS. 我知道Parallel Sets Plot,但那不是我要找的。
使用上述代码生成的桑基图,
。
我发现这篇博客文章链接到一个生成Sankey图的R脚本;不幸的是,它相当原始且有些受限(请参见下面的示例代码和数据)。
是否有人知道其他脚本或甚至是更完善的包?我的最终目标是通过图表组件的相对大小来可视化数据流和百分比,就像这些Sankey图的示例一样。
我在r-help列表上发布了一个类似的问题,但两周过去了没有任何回应,所以我在stackoverflow上试试运气。
谢谢, Eric
PS. 我知道Parallel Sets Plot,但那不是我要找的。
# thanks to, https://tonybreyal.wordpress.com/2011/11/24/source_https-sourcing-an-r-script-from-github/
sourc.https <- function(url, ...) {
# install and load the RCurl package
if (match('RCurl', nomatch=0, installed.packages()[,1])==0) {
install.packages(c("RCurl"), dependencies = TRUE)
require(RCurl)
} else require(RCurl)
# parse and evaluate each .R script
sapply(c(url, ...), function(u) {
eval(parse(text = getURL(u, followlocation = TRUE,
cainfo = system.file("CurlSSL", "cacert.pem",
package = "RCurl"))), envir = .GlobalEnv)
} )
}
# from https://gist.github.com/1423501
sourc.https("https://raw.github.com/gist/1423501/55b3c6f11e4918cb6264492528b1ad01c429e581/Sankey.R")
# My example (there is another example inside Sankey.R):
inputs = c(6, 144)
losses = c(6,47,14,7, 7, 35, 34)
unit = "n ="
labels = c("Transfers",
"Referrals\n",
"Unable to Engage",
"Consultation only",
"Did not complete the intake",
"Did not engage in Treatment",
"Discontinued Mid-Treatment",
"Completed Treatment",
"Active in \nTreatment")
SankeyR(inputs,losses,unit,labels)
# Clean up my mess
rm("inputs", "labels", "losses", "SankeyR", "sourc.https", "unit")
使用上述代码生成的桑基图,
![Sankey Diagram produced with the code above](https://istack.dev59.com/9jiMq.webp)