1

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 ?

f.a
  • 101
  • 1
  • 5
  • 14
  • Can you do a `dput` of `relations` and `vertex`? Your call to `graph.data.frame` seems right and things work when I test it locally, so it might be something with the CSV files. (Also, `read.csv` returns a data.frame, so `data.frame(nodes)` is redundant) – hrbrmstr Oct 09 '14 at 00:59
  • It is `vcount`, all lowercase. – Gabor Csardi Oct 09 '14 at 02:00
  • thanks @hrbrmstr but I did run the code without `data.frame(nodes)` but I get this error `as.data.frame.default(vertices) : cannot coerce class ""function"" to a data.frame ` so I use `data.frame(nodes)` no error but still no nodes on the screen.and about `dput` I am new to R and Igraph could you tell me a little bit more ? – f.a Oct 09 '14 at 09:36
  • thanks @GaborCsardi ,now the `vcount` function did work, but still , when I wnat to plot the network there is all edges represent by line – f.a Oct 09 '14 at 09:38
  • `dput`: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Gabor Csardi Oct 09 '14 at 19:39
  • thanks @GaborCsardi , but I didn't get how it could be of any help in here, the problem is that I see no circle as nodes on the screen just line as edges?!I can't get what is the problem in my code? – f.a Oct 09 '14 at 20:42
  • Well, **I** cannot run your code, unfortunately. So what do you expect us to do? Please give us a reproducible example that actually runs. Also, your OS, R and igraph version. Otherwise there is no way we can help. Unless somebody is a real psychic here. – Gabor Csardi Oct 09 '14 at 20:47
  • thanks.yeah I see, i was using R 3.1.1 under R studio version 0.98.978 , igraph version 0.7.1 , My OS is windows 8 -64 bit, processor intel core i7, this time I did a little change in the last line to `plot(graph_friendshipnetwork,vertex.shape="circle", vertex.color="red",layout=layout.fruchterman.reingold)` bit in the code and run it in the R itself , this time the nodes appear on the screen, no clue where the problem was still. – f.a Oct 10 '14 at 10:20

0 Answers0