简体   繁体   English

在 R 中可视化大型图网络

[英]Visualize a Large Graph Network in R

I have around 100,000 rows in a dataframe and I need to visualize it using a network graph in R.我在 dataframe 中有大约 100,000 行,我需要使用 R 中的网络图将其可视化。 However, since there is too much data, it is very difficult to analyze visually and I am not sure how to do this since I am new in R.但是,由于数据太多,很难直观地分析,我不知道该怎么做,因为我是 R 的新手。

This is what I am aiming for:这就是我的目标:

在此处输入图像描述

And this is what my df looks like:这就是我的 df 的样子:

Location地点 Manager经理
L1 L1 M1 M1
L2 L2 M3 M3
L76 L76 M1 M1
L34 L34 M1 M1
L45 L45 M1 M1
L18 L18 M4 M4
L98 L98 M7 M7
L145 L145 M4 M4
L134 L134 M1 M1
L22 L22 M5 M5
L5 L5 M7 M7
L56 L56 M7 M7
L11 L11 M8 M8
L76 L76 M5 M5

For example, location L22 should be connected to location L76 since they have M5 in common, and so on.例如,位置 L22 应该连接到位置 L76,因为它们有共同的 M5,依此类推。 I also want the weight of the line connecting these locations to be based on the number of managers they have in common.我还希望连接这些地点的线路的权重基于他们共同拥有的经理人数。

Thanks!谢谢!

I guess you can use the igraph package like below我想你可以像下面这样使用igraph package

library(igraph)
g <- simplify(
  graph_from_data_frame(
    do. Call(
      rbind,
      lapply(
        split(df, ~Manager),
        function(v) {
          with(
            v,
            if (length(Location) > 1) {
              make_full_graph(length(Location)) %>%
                set_vertex_attr(name = "name", value = Location) %>%
                set_edge_attr(name = "width", value = length(Manager)) %>%
                get.data.frame()
            } else {
              data. Frame(from = Location, to = Location, width = 1)
            }
          )
        }
      )
    ),
    directed = FALSE
  ),
  edge.attr.comb = "sum"
)

and you will obtain你会得到

> g
IGRAPH d49cf33 UN-- 13 15 -- 
+ attr: name (v/c), width (e/n)
+ edges from d49cf33 (vertex names):
 [1] L1 --L76  L1 --L34  L1 --L45  L1 --L134 L76--L34  L76--L45  L76--L22
 [8] L76--L134 L34--L45  L34--L134 L45--L134 L18--L145 L98--L5   L98--L56
[15] L5 --L56

and the network plot (run plot(g) )和网络 plot (运行plot(g)

在此处输入图像描述

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

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