简体   繁体   English

Sankey情节与riverplot软件包

[英]Sankey plot with the riverplot package

Enchanté. 结界。

EDIT: Solution 编辑:解决方案

As pointed out by MartineJ and emilliman5, nodes should be uniquely labelled (below). 正如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)

I've been toying to plot a Sankey diagram/riverplot (using the riverplot package) of how cancer registrations evolve over time, though this code has bought me little success so far. 我一直在试图绘制一个Sankey图/河流图(使用riverplot程序包)来描述癌症注册如何随着时间演变,尽管到目前为止该代码并没有给我带来多少成功。 Could anyone possibly direct me on the faults of this code? 有人可以指导我解决此代码的错误吗?

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

Here is the suspect code: 这是可疑代码:

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)

And the data, which is included in code: 以及包含在代码中的数据:

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

Eternally grateful. 永远感激不已

It looks like you're using the same value multiple times in N1 (and in N2). 看起来您在N1(和N2)中多次使用相同的值。 Try to make them all different (per column) and try again, fi: 尝试使它们全部不同(每列),然后重试,例如:

N1: plus1 minus1 plus2 minus2 N1:加1减1加2减2

If you want to show only + and -: in makeRiver, there is an option **node_labels ** 如果只想在makeRiver中显示 +和-:,则有一个选项** node_labels **

Your nodes need to be named uniquely and then use the nodes$labels to change it back: 您的节点需要唯一命名,然后使用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