简体   繁体   English

无法在R中使用igraph正确绘制图形

[英]Fail to plot the graph properly with igraph in R

Given a data frame df as below: 给定一个数据帧df ,如下所示:

df
v1             v2
tom            ben
lily           dick
ben            lily
ben            dick
.....

I tried to plot a network graph to linkage two names if they are in the same row, such as tom and ben, lily and dick,ben and lily and so on. 我试图绘制一个网络图以链接两个名称(如果它们在同一行中),例如tom和ben,lily和dick,ben和lily等。

Besides that, I also have a data frame df_size to indicate the vertex size: 除此之外,我还有一个数据框df_size指示顶点大小:

df_size
v1            v2
tom           10
lily          3
ben           1
dick          2
...

The vertex size should be proportional to their corresponding value in v2 . 顶点大小应与其在v2的对应值成比例。

And the last data frame is to classify them into groups and the color of the vertex should be the same if they are from the same group. 最后一个数据帧是将它们分为几组,如果它们来自同一组,则顶点的颜色应该相同。

df_colour
v1        v1
tom       A
lily      B
ben       A
dick      A

Now I have tried this code: 现在,我尝试了以下代码:

g = graph.data.frame(df)
plot(g,vertex.size = df_size$v2 )

But get a very bad result: 但是得到一个非常糟糕的结果:

在此处输入图片说明

Now I'd like to set the edge length and color of vertex properly, and remove the arrow. 现在,我想正确设置顶点的边缘长度和颜色,并删除箭头。 Do you have any idea to solve it? 您有解决的主意吗? Thank you in advance! 先感谢您!

Add to the plot function the commands vertex.label.cex and vertex.label.degree . 将命令vertex.label.cexvertex.label.degree添加到plot功能。 Try with this: 试试这个:

plot(g, vertex.size=8, vertex.color = rainbow(10, .8, .8, alpha= .8),
vertex.label.color = "black", vertex.label.cex = 0.4, vertex.label.degree = -pi/2,
edge.arrow.size = 0.3, edge.arrow.width = 0.4, edge.color = "black")

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

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