how to create a network having edge list and node list in two different csv file using igraph in R?

隐身守侯 提交于 2020-01-15 13:33:29

问题


what I am trying to do is to create a network using igraph in R my data includes : 1. edge list in a CSV file like this one call it book

    a  b
    1  2
    2  3
    5  1

2.node list in a CSv File like this one call it name

    c
    1
    2
    3
    4
    5

this is the code :

library(igraph)
# Import Data
relations=read.csv("book.csv",head=TRUE)
# Load (UNDIRECTED) graph from data frame 
network=graph.data.frame(relations,directed=FALSE)
ecount(network)
Vcount(network)
summary(network)
#visualizing the network
tkplot(network,vertex.shape="circle", vertex.color="red" ,vertex.size=10)

I create and plot the network with only the edge list and everything works fine but there is no nodes showing there and when I use the Vcount(network) I get this error:could not find function "Vcount" but in summary I got for example : IGRAPH UN--20 111 -- attr: name (v/c)

I think that I should use the data.frame to specify the nodes but I don't know how?(using this [http://www.inside-r.org/packages/cran/igraph/docs/graph.data.frame])

I try this code but it dosen't work :

library(igraph)
# Import Data
relations=read.csv("book.csv",head=TRUE)
nodes=read.csv("name.csv",head=TRUE)
vertex=data.frame(nodes)
# Load (UNDIRECTED) graph from data frame 
network=graph.data.frame(relations,directed=FALSE,vertices=vertex)
ecount(network)
Vcount(network)
summary(network)
#visualizing the network
tkplot(network,vertex.shape="circle", vertex.color="red" ,vertex.size=10)

when I run summary(network) everything is right but still I got the Vcount error and again in tkplot still no nodes just the edges .... How should I fix this ?

来源:https://stackoverflow.com/questions/26268161/how-to-create-a-network-having-edge-list-and-node-list-in-two-different-csv-file

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!