如何在 R 中为简单网络图添加标签?提供代码

问题描述

我正在使用以下代码加载佛罗伦萨数据集并尝试可视化网络:

library("ergm")
data("florentine")
require(intergraph)
require(igraph)
marriages <- asIgraph(flomarriage)

# Calculate degree centrality
V(marriages)$degree <- degree(marriages)

# Plot
plot(marriages,vertex.label.cex = .6,vertex.label.color = 'blue')

结果:

Network

问题:节点有编号,而不是数据集中存在的家族名称(称为vertex.names)。如何用名称替换节点号?例如。有我可以使用的标签功能吗?

解决方法

# ?igraph.plotting
plot(marriages,vertex.label = V(marriages)$vertex.names)

该参数记录在您找到您使用的其他参数的页面上。