当然,您可以更优雅地执行此操作,但其中一个选项可能是重塑数据,以便有两个边列表,然后将它们合并。
library(igraph)
data<-data.frame(Employee=paste0("E", c(1:5)),
Address=paste0("A", c(1:3,1,3)),
Designation=paste0("D", c(1:3,2,3)))
g1<-graph.adjacency(tcrossprod(table(data[,c(1,2)])), diag=FALSE, mode="undirected")
el<-get.data.frame(g1)
el$e_type<-"Address"
g2<-graph.adjacency(tcrossprod(table(data[,c(1,3)])), diag=FALSE, mode="undirected")
el2<-get.data.frame(g2)
el2$e_type<-"Designation"
el_all<-rbind(el, el2)
final_g<-graph.edgelist(as.matrix(el_all[,1:2]))
E(final_g)$type<-el_all[,3]
E(final_g)$color<-ifelse(E(final_g)$type=="Address", "red", "blue")
plot(final_g)