我有一个所有用户的关联网络以及他们如何根据他们的角色相互连接,我做了以下情节:
plot(
net,
vertex.frame.color=ifelse(V(net)$Team==TeamName, "black",NA),
vertex.size=ifelse(V(net)$Team==TeamName, 5, 0),
vertex.label=ifelse(V(net)$Team==TeamName, NA, NA),
edge.arrow.mode=0,
edge.lty=0,
vertex.color=ifelse(V(net)$Team==TeamName, "skyblue", NA))
导致:所有用户,但仅限某个团队的用户进行比对 我想要做的是添加每个用户更改vertex.label的名称,但这会使情节混乱。因为用户非常接近。
plot(
net,
vertex.frame.color=ifelse(V(net)$Team==TeamName, "black",NA),
vertex.size=ifelse(V(net)$Team==TeamName, 5, 0),
vertex.label=ifelse(V(net)$Team==TeamName, V(net)$internalname, NA),
edge.arrow.mode=0,
edge.lty=0,
vertex.color=ifelse(V(net)$Team==TeamName, "skyblue", NA))
另一件事是我们感觉缩小了,如果情节将以可见用户为中心(ifelse(V(net)$Team==TeamName
)会更好,我正在考虑子图但我无法弄清楚如何做那真是太棒了。我不知道这是否是解决方案。
我也试过这个,这个情节告诉我,我的所有用户都是相等的,之前的情节没有。
tem <-delete.vertices(net,V(net)$Team!=TeamName)
plot(tem, vertex.label= round(closeness(tem, mode="all", weights=NA),2))
一些额外信息,因为我无法共享个人数据
用作边的数据帧(x是共享连接的数量)
$ acentralacc: chr
$ bcentralacc: chr
$ x : int
用作顶点的数据框
$ CentralAccount: chr
$ internalname : chr
$ Team : Factor
这应该生成示例数据
install.packages("plyr")
library(plyr)
#data1 (edges)
n<-100
acentralacc<- paste("user",sample(1:n, 1000,replace=TRUE)) #usera
bcentralacc<- paste("user",sample(1:n, 1000,replace=TRUE)) #userb
x<- sample(1:100, 1000,replace=TRUE) #x
data1 <- data.frame(acentralacc,bcentralacc,x)
head(data1)
#users (vertices)
centralacc <- unique(append(acentralacc, bcentralacc))
Team<- paste("Team",sample(1:round(n/3,0), length(centralacc),replace=TRUE))
users<-data.frame(centralacc,Team)
head(users)
其他代码
users$Team <- iconv(users$Team, "ASCII", "UTF-8", sub="")
users$Team <- factor(users$Team)
#creating the igraph
net <- graph_from_data_frame(d=data1, vertices=users, directed=T)
#the following should be igraph
class(net)
#removing fields with no links (0 degree)(users with no connections)
length(net[1])
net <- delete.vertices(simplify(net), degree(net)==0)
length(net[1])
#removing graphical loops etc users that have connections to them self
net <- simplify(net, remove.multiple = F, remove.loops = T)