从直观上看,所谓图就是由点与边组成的图形,如下图所示:

定义:图G是一个偶对(V,E),其中V是一个非空集合,其元素u属于V称为图的定点;E是由V中的点构成的点对,E的元素e称为图的变或弧。若e是无序对,则称G为无向图,否则则成为有向图。若e=(u,v),则称u为e的起点,v为e的终点。称去掉有向图的方向得到的图为基础图
在igraph中可用graph函数构件图,其使用格式为:
make_graph(
edges,
...,
n = max(edges),
isolates = NULL,
directed = TRUE,
dir = directed,
simplify = TRUE
)
make_directed_graph(edges, n = max(edges))
make_undirected_graph(edges, n = max(edges))
directed_graph(...)
undirected_graph(...)
Arguments
其中:
#install.packages("igraph")
library(igraph)
e=c(1,2,2,2,2,4,1,4,3,1,3,4,4,3,4,5)
par(mfrow=c(1,2))#把图形分割为两部分
enames <- paste("e",1:8,sep="")
g1 <- graph(e,directed = F)
g2 <- graph(e)
plot(g1,layout=layout.circle,edge.label=enames)
plot(g2,layout=layout.circle,edge.label=enames)

如图所示,把左边的这个图变成右边:
as.directed(graph,mode=c("mutual","arbitrary","each","random"))
library(tidyverse)
plot(g1,layout=layout.circle,edge.label=enames)#无向图
as.directed(g1,mode="mutual") %>% plot(layout=layout.circle,edge.label=enames)

graph.empty函数
graph.empty(n=0,directed = T) %>% plot()
结果如下:

E <- c(1,2,1,3,2,3,3,5,3,4,3,6,3,7,4,5,4,9,5,1,5,6,7,1,7,8,
8,2,8,5,8,9,9,5,9,10,10,6)
g3 <- graph.empty()+vertices(letters[1:10])
g3 <-g3+ edges(E)
plot(g3,layout=layout.circle)

用到graph.fromula函数
graph.full()函数
graph.ring()函数
graph.formula(A-+B-+C) %>% plot()
graph.formula(A+-B-+C) %>% plot()
graph.formula(A+-B--C) %>% plot()


graph.lattice(c(2,2,2)) %>% plot()
graph.full(5) %>% plot()
graph.ring(10) %>% plot()
