簡體   English   中英

Sankey情節與riverplot軟件包

[英]Sankey plot with the riverplot package

結界。

編輯:解決方案

正如MartineJ和emilliman5所指出的,節點應該被唯一地標記(如下)。

library("riverplot")
nodes<-structure(list(ID = c("2011+", "2011-", "2016+", "2016-"), x = c(20, 
20, 30, 30), y = c(50, 40, 50, 40)), class = "data.frame", row.names = c(NA, 
-4L))
edges<-structure(list(N1 = c("2011+", "2011-", "2011+", "2011-"), N2 = 
c("2016+", "2016-", "2016-", "2016+"), Value = c(461, 7, 0, 46)), class = 
"data.frame", row.names = c(NA, -4L))

river <- makeRiver(nodes,edges)
riverplot(river)

我一直在試圖繪制一個Sankey圖/河流圖(使用riverplot程序包)來描述癌症注冊如何隨着時間演變,盡管到目前為止該代碼並沒有給我帶來多少成功。 有人可以指導我解決此代碼的錯誤嗎?

Warning message: In checkedges(x2$edges, names(x2)) : duplicated edge information, removing 1 edges

這是可疑代碼:

library(“riverplot”)

edges<-structure(list(N1 = c("+", "-", "+", "-"), N2 = c("+", "-", "-", "+"), Value = c(664L, 50L, 0L, 46L)), .Names = c("N1", "N2", "Value"), class = "data.frame", row.names = c(NA, -4L))

nodes = data.frame(ID = unique(c(edges$N1, edges$N2)), stringsAsFactors = FALSE)

nodes$x = c(1,2)
rownames(nodes) = nodes$ID

rp <- list(nodes=nodes, edges=edges)

class(rp) <- c(class(rp), "riverplot")

plot(rp)

以及包含在代碼中的數據:

N1    N2    Value
 +     +     664
 -     -      50
 +     -       0
 -     +      46

永遠感激不已

看起來您在N1(和N2)中多次使用相同的值。 嘗試使它們全部不同(每列),然后重試,例如:

N1:加1減1加2減2

如果只想在makeRiver中顯示 +和-:,則有一個選項** node_labels **

您的節點需要唯一命名,然后使用nodes$labels將其更改回:

library(riverplot)

edges<-structure(list(N1 = c("+", "-", "+", "-"), N2 = c("+", "-", "-", "+"), Value = c(664L, 50L, 0L, 46L)), .Names = c("N1", "N2", "Value"), class = "data.frame", row.names = c(NA, -4L))
edges$N1 <- paste0(edges$N1, "a")
edges$N2 <- paste0(edges$N2, "b")
nodes = data.frame(ID = unique(c(edges$N1, edges$N2)), stringsAsFactors = FALSE)

nodes$x = c(1,1,2,2)
nodes$labels <- as.character(substr(nodes$ID, 1, 1))
rownames(nodes) = nodes$ID

rp <- list(nodes=nodes, edges=edges)

class(rp) <- c(class(rp), "riverplot")

plot(rp)

在此處輸入圖片說明

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM