在r

时间:2019-05-29 13:34:22

标签: r igraph ggraph tidygraph

我目前正在尝试使用r(最好是使用ggraph)创建圆形二部图。我有一个雌雄蛙交配关系的数据集;这是该数据的子集:

Mother    Father
M1        F1
M2        F2
M3        F2
M4        F3
M5        F4
M6        F4
M7        F4

我的目标是可视化每个生物体具有的伴侣数量,如下所示:

concentric bipartite graph showing relationships between mother and father organisms

到目前为止,我已经能够使用igraph制作图的线性版本:

> library(tidyverse)
> library(igraph)
> library(ggraph)
> MyData <- read_csv("Bipartite.csv")
> Visualization <-graph.data.frame(MyData)
> bipartite.mapping(Visualization)

$res
[1] TRUE
 $type
[1] FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE FALSE  
TRUE  TRUE  TRUE
[14]  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE  TRUE


> V(Visualization)$type <- bipartite_mapping(Visualization)$type
> plot(Visualization, layout = layout.bipartite)

哪个产生了: Linear bipartite graph showing mating relationships between mothers and fathers; very tangled and hard to read as labels overlap

我一直坚持将其转换为圆形可视化。我尝试过的两件事是:

首先,将igraph对象放入ggraph并以“圆形”布局进行绘制:

> ggraph(Visualization, layout = 'circle') 
+ geom_edge_link() 
+ geom_node_point()

但是,我得到的不是一个同心的圆环,而是一个大圆圈,它对显示数据没有用(我知道,可以仅通过ggraph来完成它)。

Single-ring visualization of mating data, with both mothers and fathers in a single ring

第二,我尝试将igraph对象带入ggraph并将circular设置为TRUE:

ggraph(Visualization, layout = 'bipartite', circular = TRUE) 
+ geom_edge_link() 
+ geom_node_point()

但是我收到错误消息:

Error in layout_igraph_igraph(graph, layout, circular, ...) :
Circular layout only applicable to tree and DAG layout

关于如何生成所需的可视化效果的任何想法?我对r和stackoverflow都很陌生,因此我对解释我的问题的任何限制表示歉意。谢谢!

0 个答案:

没有答案