How to plot relationships in R?

浪尽此生 提交于 2019-12-08 01:52:33

问题


The relationship is expressed as a matrix x like this:

      John Jack Mary Wendy
John     0    2    1     1
Jack     2    0    1     0
Mary     1    1    0     1
Wendy    1    0    1     0

The entries refer to the number of connections they have. Could anyone show me how to plot it as a network in R? Thanks!


回答1:


This is known as an adjacency matrix.

There is some information in the R FAQ on plotting social networks expressed as matrices:

Plotting social network data can be easily done with the igraph package in R. [...] In order for the igraph package to recognize this table as a network, we can first convert it to a matrix. Then, if we wish to calculate graph-related statistics on it (betweenness, closeness, degree), we can use the matrix to create a graph object.

The FAQ gives some examples, resulting in sociogram diagrams, for example:

The igraph library itself is documented here - it can produce much more complex examples - see the screenshots page and the example below:



来源:https://stackoverflow.com/questions/13203778/how-to-plot-relationships-in-r

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!