简体   繁体   English

带R(或相关)的冲积图

[英]Alluvial diagram with R (or related)

In a survey I asked two question: 在一项调查中,我问了两个问题:

  1. What is your main transportation?(only 1 possible answer and mandatory answer) 您的主要交通工具是什么?(仅一个可能的答案和一个强制性的答案)
  2. What is your secondary transportation? 你的二次交通工具是什么? (0 or many answer, each secondary transport contains 0 for yes and 1 for no) (0个或多个答案,每个辅助传输包含0表示是和1表示否)

Here are some fake data: http://pastebin.com/raw.php?i=pp1EHP7r 以下是一些虚假数据: http : //pastebin.com/raw.php?i=pp1EHP7r

PersonNumber,Main Transport,Bus(secondary transport),Metro(secondary transport),Tram (secondary transport)
1,Bus,1,0,1
2,Bus,1,0,1
3,Bus,1,1,1
4,Train,1,0,0
5,Train,0,1,0
6,Train,0,1,0
7,Bus,0,0,0
8,Bus,0,1,0
9,Metro,0,1,0

My aim is to create two parts The left part with the main transports. 我的目的是创建两个部分,左侧是主要运输工具。 The right part with secondary transport. 右侧部分带有二次运输。 Then the left tranport link the right one if there is the value one on the right column. 然后,如果右侧列上的值为1,则左侧运输链接右侧的运输。 For instance for the first observation : Bus will be linked to Bus(secondary transport) and to Tram (secondary transport) but not to Metro(secondary transport) 例如,第一次观察:公交车将链接到公交车(二次运输)和电车(二次运输),但不会链接到地铁(二次运输)

I really don't know how to do it because one main transport needs to be connected to many other columns only if values contains 1... 我真的不知道该怎么做,因为只有当值包含1时,一个主要传输才需要连接到许多其他列。

I'm looking for that kind of graph flow http://app.raw.densitydesign.org/#/ 我正在寻找这种图形流http://app.raw.densitydesign.org/#/

If you want to visualize it using Raw ( http://app.raw.densitydesign.org/#/ ) you have to create a dataset like this (created starting from your data): 如果要使用Raw( http://app.raw.densitydesign.org/#/ )对其进行可视化,则必须创建一个这样的数据集(从数据开始创建):

PersonNumber    MainTransport   SecondaryTransport
1   Bus Bus
1   Bus Tram
2   Bus Bus
2   Bus Tram
3   Bus Bus
3   Bus Tram
3   Bus Metro
4   Train   Bus
5   Train   Metro
6   Train   Metro
8   Bus Metro
9   Metro   Metro

Each line represents a connection between main transport and secondary transport. 每条线代表主要运输和次要运输之间的连接。 If a person uses more than one secondary transport, you must create a line for each couple of primary/secondary transport (see person #3). 如果一个人使用多个辅助运输工具,则必须为每对主要/辅助运输工具创建一条线路(请参见第3个人)。 Be aware that as each line have the same visual weight, the total height of the fluxes represents the number of each variable occurrences. 请注意,由于每条线的视觉权重相同,所以通量的总高度表示每个变量出现的次数。

In Raw drag "MainTransport" and "SecondaryTransport" as "Dimensions". 在原始拖动中,将“ MainTransport”和“ SecondaryTransport”拖动为“ Dimensions”。

If you want to add color to the graph you need to modify alluvial.js by swapping the color variable: 如果要向图形添加颜色,则需要通过交换color变量来修改alluvial.js:

color = d3.scale.category20(); color = d3.scale.category20();

Then it works like a charm! 然后,它就像一个魅力!

Rob

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM