R language to draw various graphics

R language draws a directed graph of five nodes

library(igraph)
g2 <- graph(edges=c(1,4,1,3,1,2,1,5,2,4,2,3,2,5), n=5)%>%set_vertex_attr("color", 
value ='cadetblue')%>%set_edge_attr("color", value ='brown')%>%set_vertex_attr("shape", value ='sphere')
plot(g2)   

Insert image description here
R language to draw the famous bull network diagram

library(igraph)
g <- make_graph("Bull")%>%set_vertex_attr("color", value ='cadetblue')%>%set_edge_attr("color", 
value ='brown')%>%set_vertex_attr("shape", value ='sphere')%>%set_edge_attr('arrow.mode',
value =3)%>%set_edge_attr('arrow.width',value=1.5)%>%set_edge_attr('width',value=4)
bridges(g)
plot(g)

Insert image description here
R language to draw a one-way directed star graph

library(igraph)
g <- make_ring(10)%>%set_edge_attr('arrow.mode', value =2)%>%set_vertex_attr("color", 
value ='violet')%>%set_edge_attr("color", value ='slategray')%>%set_vertex_attr("shape", value ='sphere')
as.directed(g, "mutual")
plot(g)

Insert image description here
R language to draw a star diagram with 10 nodes

library(igraph)
g2 <- make_star(10)%>%set_edge_attr('arrow.mode', value =2)%>%set_vertex_attr("color", 
value ='cadetblue')%>%set_edge_attr("color", value ='brown')%>%set_vertex_attr("shape", value ='sphere')
as.undirected(g2)
plot(g2)

Insert image description here
R language drawing sliding window

library(igraph)
g3 <- make_ring(10, directed = TRUE, mutual = FALSE)%>%set_vertex_attr("color", 
value ='cadetblue')%>%set_edge_attr("color", value ='brown')%>%set_vertex_attr("shape", value ='sphere')
E(g3)$weight <- seq_len(ecount(g3))
ug3 <- as.undirected(g3)%>%set_vertex_attr("color", 
value ='cadetblue')%>%set_edge_attr("color", value ='brown')%>%set_vertex_attr("shape", value ='sphere')
print(ug3, e = TRUE)
## 没有运行:
x11(width = 10, height = 5)
layout(rbind(1:2))
plot(g3, layout = layout_in_circle, edge.label = E(g3)$weight)
plot(ug3, layout = layout_in_circle, edge.label = E(ug3)$weight)
IGRAPH ec63084 U-W- 10 10 -- Ring graph
+ attr: name (g/c), mutual (g/l), circular (g/l), color (v/c), shape (v/c), weight (e/n), color (e/c)
+ edges from ec63084:
 [1] 1-- 2 2-- 3 3-- 4 4-- 5 5-- 6 6-- 7 7-- 8 8-- 9 1--10 9--10

A directed one-way star graph can also be understood as a sliding window
Insert image description here
A directed two-way star graph can also be understood as a sliding window

g3 <- make_ring(10, directed = TRUE, mutual = TRUE)%>%set_vertex_attr("color", 
value ='cadetblue')%>%set_edge_attr("color", value ='brown')%>%set_vertex_attr("shape", value ='sphere')

Insert image description here
References: "Network Analysis and Visualization"
https://kateto.net/netscix2016.html
Development tools: RStudio and WeChat Alt+A screenshot tool

Guess you like

Origin blog.csdn.net/m0_38127487/article/details/132645065