微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

R中清晰的igraph网络图

如何解决R中清晰的igraph网络图

使用R库'igraph',我创建了一个网络图,该图显示了人群之间的“关系”(例如,personA向PersonB出售汽车,PersonB向PersonC出售汽车,PersonC单元向personB出售汽车)。 / p>

这是我创建的虚假数据(数字对应于每个人的ID)和结果图:

library(igraph)
 
#create first file
x5 <- sample(1:100,50,replace=T)
#create second file
x4 <- sample(1:100,replace=T)

#combine files
a = cbind(x4,x5)
#convert to data frame
a = data.frame(a)

#convert to factor
a$x4 = as.factor(a$x4)
#convert to factor
a$x5 = as.factor(a$x5)

#convert to matrix
a = as.matrix(a)

#create graph
graph_object = graph_from_edgelist(a)

#plot graph
plot(graph_object)

这是我想要的,但是我有一个问题。在我的实际数据中,有成千上万的人,他们的ID长几个数字。这意味着,当我在具有较长ID的更多人上运行以下代码时,结果图变得非常混乱和拥挤,无法读取。

这是一个更接近我的情况的例子:

library(igraph)
library(dplyr)

#create file from which to sample from
x5 <- sample(1:1000000000,2000,replace=T)
#convert to data frame
x5 = as.data.frame(x5)

#create first file (take a random sample from the created file)
a = sample_n(x5,1000)
#create second file (take a random sample from the created file)
b = sample_n(x5,1000)

#combine
c = cbind(a,b)
#create dataframe
c = data.frame(c)
#rename column names
colnames(c) <- c("a","b")

#convert to factors
c$a = as.factor(c$a)
c$b = as.factor(c$b)

#convert to matrix
c = as.matrix(c)
#create graph
graph_object = graph_from_edgelist(c)
#plot graph
plot(graph_object)

是否可以更改此图的输出以使其变得更混乱?是否可以“隐藏”输出中的ID,即在将鼠标光标移到节点上时显示ID,或在节点上单击时显示ID?还是可以显示的节点数量有数学上的限制?

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。