r - 在 R 中使用 igraph 创建网络图

标签 r igraph

<分区>

我需要一些帮助才能开始在 R 中使用 igraph。我有一个包含三列的 .csv 文件:

  1. 第一列是一个字符串,表示“from”节点,
  2. 第二列是一个String,代表“to”节点,然后
  3. 第三列是表示关系强度的 Double。

我已将文件读入 R,并尝试将其转换为数据框并以这种方式绘制图形,但没有成功。 我的最终目标是将此 .csv 文件转换为加权网络图,但我不确定如何开始。

最佳答案

这个(来自 igraph 文档的改编示例)应该让你开始:

# Load package
library(igraph)

# Make up data
relations <- data.frame(from=c("Bob", "Cecil", "Cecil", "David", "David", "Esmeralda"),
                        to=c("Alice", "Bob", "Alice", "Alice", "Bob", "Alice"),
                        weight=c(4,5,5,2,1,1))
# Alternatively, you could read in the data from a similar CSV file as follows:
# relations <- read.csv("relations.csv")

# Load (DIRECTED) graph from data frame 
g <- graph.data.frame(relations, directed=TRUE)

# Plot graph
plot(g, edge.width=E(g)$weight)

enter image description here

关于r - 在 R 中使用 igraph 创建网络图,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23687806/

相关文章:

r - 用R计算一个顶点(节点)的局部聚类系数(手工)

windows - 错误 : C stack usage is too close to the limit in Windows environment

R Shiny HTML 对象在每个 tabPanel() 上呈现

在 R 中运行包含求和的非线性 (nls) 回归

r - 卸载所有加载的包

r - 跟踪网络中的连接?

r - 记录 Shiny 的应用程序

r - igraph中的子组件失败

r - igraph 显示绘图上的所有顶点,即使有一些边

r - 社交图分析。 60GB 和 1 亿个节点