在 R 中使用 igraph 创建图形结构

问题描述

我正在尝试在 R 中使用 igraph 重现以下图。

graph

我有以下代码

library(igraph)
edges <- c(1,2,3,6,8,7,4,5,9,10)
g<-graph(edges,n=max(edges),directed=F)
vcount(g)

plot(g,layout = layout.fruchterman.reingold,vertex.label=V(g)$number,edge.arrow.size=0.5)

mygraph

我不确定如何创建图的拓扑结构并生成完全相同的图。

解决方法

使用 layout= 参数指定位置,使用 V(g)$colorE(g)$lty 指定顶点颜色和边线类型。

library(igraph)

edges <- c(1,2,3,6,8,7,4,5,9,10,1,10)
x <- c(2,5)
y <- c(5:1,5:1)

g <- graph(edges,n=max(edges),directed = FALSE)
V(g)$color <- "yellow"
E(g)$lty <- c(rep(1,6),3)
plot(g,layout = cbind(x,y))

给予

screenshot

,
library(igraph)
edges <- c(1,10)
g<-graph(edges,directed=F)
E(g)$lty <- c(rep(1,length(E(g))-2),rep(2,2))
plot(g)

enter image description here