2

我尝试使用 R 中的 Riverplot 包创建一个带有固定节点和边缘颜色的 sankey 图。颜色在 .csv 文件中以单独的颜色给出

library(riverplot)

# import data
edges = read.csv("sankey_data_edges.csv")

nodes = read.csv("sankey_data_nodes.csv")


r <- makeRiver(nodes, edges)
plot( r )

sankey_data_nodes.csv包含:

ID  x   labels  y   col
1   1   G1  2   green
2   1   G2  1   red
3   3   G3  3   red
4   3   G4  2   red
5   1   G5  6   red
6   1   G6  5   red
7   4   G7  6   red
8   2   G8  4   red
9   1   G9  3   red
10  1   G10 4   red
11  3   G11 6   red
12  3   G12 4   red

sankey_data_edges.csv包含:

N1  N2  Value   col edgecol
5   4   0.098870056 yellow  col
1   11  0.124105534 red col
5   3   0.163841808 red col
2   11  0.175207813 red col
10  8   0.214996976 red col
5   12  0.330508475 red col
5   11  0.406779661 red col
9   8   0.485689676 red col
8   11  0.700686653 red col
11  7   1   red col
6   11  1   red col

不幸的是,根据设置的颜色,结果不是应该的: 河图结果

错误:

  • 无绿色节点(ID=1)
  • 边缘是黑色而不是红色和一个黄色
4

1 回答 1

1

您必须确保包含颜色的列是字符类型。标准 read.csv 使它们成为因素,也许使用 stringsAsFactors=FALSE。

于 2017-06-20T14:45:15.610 回答