英文:
Visualize the links between two lists
问题
我有一个由两个名为A和B的个体列表以及它们之间的关系R组成的表,R的值可以是0、1或2。
我想创建一个图表,其中列表A在一边,列表B在另一边,两个列表中的项目根据R的值以不同颜色连接在一起。
对如何实现此目标有任何想法或建议都将不胜感激!
因此,数据看起来像这样:
A, B, R
A1, B1, 0
A1, B2, 2
A1, B3, 0
A2, B1, 1
A2, B2, 0
A2, B3, 1
A3, B1, 0
A3, B2, 0
A3, B3, 2
英文:
I have a table made with two lists A and B of individuals and their relationship R that can either take the values of 0, 1, or 2.
I want to create a graph where I have the list A on one side, the list B on the other side and items on both lists linked together with a different color depending on the value of R.
Any idea or suggestion on how to do it much appreciated!
So the data looks something like :
A, B, R
A1, B1, 0
A1, B2, 2
A1, B3, 0
A2, B1, 1
A2, B2, 0
A2, B3, 1
A3, B1, 0
A3, B2, 0
A3, B3, 2
答案1
得分: 1
plot(igraph::graph_from_data_frame(df, FALSE),
edge.color = df$R + 1,
layout = as.matrix(rev(expand.grid(1:3, 1:2))))
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论