我試圖想象我有一個熱平衡圖數據流R.R的Sankey圖?
我發現this blog post鏈接到產生熱平衡圖的R腳本,不幸的是它是相當原始和比較有限(見下面的示例代碼和數據)。
有沒有人知道其他腳本 - 或者甚至是一個包 - 更發達?我的最終目標是通過圖組件的相對大小顯示數據流和百分比,如these examples of Sankey Diagrams。
我貼a somewhat similar question on the r-help list,但兩週後沒有任何反應,我想我的運氣在這裏在stackoverflow。
感謝, 埃裏克
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")
熱平衡圖產生與上面的代碼,
箭頭看起來沒什麼問題,看起來像你留下了微調的文字和你的? – 2012-04-03 08:09:54
@羅曼Luštrik,我同意,這個圖並不差,但我的R技能仍然有限,所以我不能在R中做那麼多的微調,如果那是你的意思?我當然可以用Adobe Illustrator或類似的軟件來做,但這會違反可重複研究的原則,這對我來說是任何(學術)工作的核心要素。你看過[我在帖子中鏈接到的例子](http://www.sankey-diagrams.com/tag/software/)嗎? – 2012-04-03 17:52:13
我意識到我的問題不是一個好問題,它不是一個特定的編程問題,也不是直接實用的問題,而是一個有些開放式問題(來自FAQ)(http://stackoverflow.com/faq) )。要回答這個問題,人們必須對R中不同的圖形選項進行監督,並在此基礎上用_no來回答我的問題,那裏沒有任何更開發的代碼或包,或者需要知道在R中生成Sankey Diagrams並指向它的更爲成熟的方法。也許有更好的地方發佈這個問題? – 2012-04-03 18:01:47