简体   繁体   English

在 R 中使用 igraph 创建图结构

[英]Creating a graph structure using igraph in R

I am trying to reproduce the following plot using igraph in R.我正在尝试使用 R 中的igraph重现以下 plot。

图形

I have the following code:我有以下代码:

library(igraph)
edges <- c(1,2, 2,3, 6,8, 6,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)

我的图

I am not sure how to create the topology of the graph and produce the exact same graph.我不确定如何创建图的拓扑并生成完全相同的图。

Use the layout= argument to specify the positions and V(g)$color and E(g)$lty to specify the vertex color and edge line types.使用layout=参数指定位置,使用V(g)$colorE(g)$lty指定顶点颜色和边线类型。

library(igraph)

edges <- c(1,2, 2,3, 6,8, 6,7, 4,5, 9,10, 1,6, 5,10)
x <- c(2, 1, 2, 1, 2, 5, 6, 5, 6, 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, 3)
plot(g, layout = cbind(x, y))

giving给予

截屏

library(igraph)
edges <- c(1,2, 2,3, 6,8, 6,7, 4,5, 9,10, 1,6, 5, 10)
g<-graph(edges, n=max(edges), directed=F)
E(g)$lty <- c(rep(1, length(E(g))-2), rep(2,2))
plot(g)

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM