Riverplot包在R - Sankey图颜色

时间:2016-06-30 07:25:23

标签: r visualization sankey-diagram riverplot

我尝试使用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

不幸的是,结果不是根据设定的颜色应该是什么: Riverplot result

错误:

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

1 个答案:

答案 0 :(得分:1)

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