你可以试试graph_from_adjacency_matrix++tcrossprodtable
library(igraph)
g <- graph_from_adjacency_matrix(as.dist(tcrossprod(table(df))))
Run Code Online (Sandbox Code Playgroud)
并plot(g)显示如下网络
另一种方法是bipartite.projection
df %>%
graph_from_data_frame() %>%
set_vertex_attr(name = "type", value = names(V(.)) %in% df$Shop) %>%
bipartite.projection() %>%
pluck(2) %>%
plot()
Run Code Online (Sandbox Code Playgroud)
数据
> dput(df)
structure(list(Shop = c("S1", "S1", "S2", "S2", "S3", "S4"),
Manager = c(34L, 12L, 11L, 34L, 34L, 50L)), class = "data.frame", row.names = c(NA,
-6L))
Run Code Online (Sandbox Code Playgroud)