从dataframe列创建igraph

从dataframe列创建igraph,r,igraph,R,Igraph,我尝试从名为routes$Source Airport和routes$Destination Airport的数据帧列中创建一个igraph 我打字 g<-graph.formula("routes$Source Airport","routes$Destination Airport") plot.igraph(g) g在变量名中使用空格是个坏主意。让我们用source和dest代替变量名: dat <- data.frame(source=1:3, dest=c(3, 1, 1

我尝试从名为
routes$Source Airport
routes$Destination Airport
的数据帧列中创建一个igraph 我打字

g<-graph.formula("routes$Source Airport","routes$Destination Airport")
plot.igraph(g)

g在变量名中使用空格是个坏主意。让我们用
source
dest
代替变量名:

dat <- data.frame(source=1:3, dest=c(3, 1, 1))

g <- graph.data.frame(dat)
plot(g)