网络:使用igraph从事件节点数据制作图形对象 [英] Network: Making Graph Object from Event-Node Data Using igraph

查看:129
本文介绍了网络:使用igraph从事件节点数据制作图形对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想根据事件注释数据为igraph制作网络对象.

I want to make a network object for igraph from a event-note data.

例如,我的数据看起来像这样.

For example, I have a data looks like this.

 Event  Person
  1     Obama
  1     Putin
  1     Abe
  1     Cameron 
  2     Putin
  2     Xi
  2     Merkel
  3     Obama
  3     Abe
  3     Xi
  3     Merkel

我假设同一事件中的每个人都有联系.奥巴马,普京,安倍和卡梅隆之间有联系,因为他们都在事件1中.根据此数据,奥巴马和安倍有两次联系,因为它们都在事件1和3中.

I assume everybody in same event has connections. Obama, Putin, Abe, and Cameron have connections, because they are all in event 1. Based on this data, Obama and Abe have two times of connection because they are both in event 1 and 3.

使用此数据,我想计算度数/中间度/接近度中心度.要计算这些中心性,我需要有一个图形对象.如何创建图形对象或邻接矩阵以计算三个中心度度量?

With this data, I want to calculate degree / betweenness / closeness centrality. To calculate these centralities, I need to have a graph object. How can I create a graph object or adjacency matrix to calculate three centrality measures?

对于这个基本问题,我们感到很抱歉,但是我是第一次使用R进行网络分析.

I am sorry for this basic question, but I am new to using R for network analysis.

提前谢谢!

推荐答案

假设您将数据读入名为dd的data.frame,则可以使用

Assuming you read your data into a data.frame named dd, you can get an adjacent matrix with

X <- with(dd, table(Event, Person))
adj <- crossprod(X,X)

#          Person
# Person    Abe Cameron Merkel Obama Putin Xi
#   Abe       2       1      1     2     1  1
#   Cameron   1       1      0     1     1  0
#   Merkel    1       0      2     1     1  2
#   Obama     2       1      1     2     1  1
#   Putin     1       1      1     1     2  1
#   Xi        1       0      2     1     1  2

关于如何将其转换为图形对象的方法,您有一些选择,但是最有可能使用graph.adjacency.这是一种方法

You have a few options on how you want to turn that into a graph object, but you'd most likely use graph.adjacency. Here's one way

gg<-graph.adjacency(adj, mode="upper", weighted=TRUE, diag=FALSE);
plot(gg,  edge.width=E(gg)$weight)

这篇关于网络:使用igraph从事件节点数据制作图形对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆