为什么我的河图如此怪异?

时间:2017-09-20 10:33:10

标签: r data-visualization riverplot

我试图生成一个河流图,但我看起来像边缘的输出来自每个条的错误一侧,这使得难以解释。 enter image description here

我使用的数据是:

边缘:

       N1       N2      Value
1     off    off.1 0.77149877
2    weak    off.1 0.47474747
3  medium    off.1 0.17537313
4  strong    off.1 0.03603604
5     off    low.1 0.06879607
6    weak    low.1 0.26262626
7  medium    low.1 0.13432836
8  strong    low.1 0.01351351
9     off medium.1 0.12530713
10   weak medium.1 0.23232323
11 medium medium.1 0.54850746
12 strong medium.1 0.20720721
13    off strong.1 0.03439803
14   weak strong.1 0.03030303
15 medium strong.1 0.14179104
16 strong strong.1 0.74324324

节点:

        ID x y
1      off 1 4
2     weak 1 3
3   medium 1 2
4   strong 1 1
5    off.1 2 4
6    low.1 2 3
7 medium.1 2 2
8 strong.1 2 1

并且情节的代码是:

library(RColorBrewer)
library(riverplot)
palette = paste0(brewer.pal(5, "Set2"), "60")
styles = lapply(nodes$y, function(n) {
  list(col = palette[n+1], lty = 0, textcol = "black")
})
names(styles) = nodes$ID
nlabels <- c(off = 'off', weak = 'weak', medium = 'medium',strong = 'strong', 
             off.1 = 'off', weak.1 = 'weak', medium.1 = 'medium', strong.1 = 'strong')
x <- makeRiver(nodes, edges, node_styles = styles, node_labels = nlabels)
plot(x)

1 个答案:

答案 0 :(得分:2)

可以解决问题,指定图上节点的垂直位置(nodes_ypos选项):

x <- makeRiver(nodes, edges, node_styles = styles, node_labels = nlabels,
               node_ypos=1:4)
plot(x)

enter image description here

使用sankeyNetwork的{​​{1}}功能,您可以获得类似(互动)的情节:

networkD3

enter image description here