I'm working with data.frames with columns "from" and "to" and I would like to create network graphs from them.
For example:
mydata <- data.table(from=c("John", "John", "Jim", "Jesse"),
to=c("John", "Jim", "Jack", NA))
mygraph <- graph_from_data_frame(d=mydata, directed=T)
plot(mygraph, vertex.label.dist=2)
The presence of that NA produces an error.
If I just remove the NA row the lonely node is not plotted.
mydata <- data.table(from=c("John", "John", "Jim"),to=c("John", "Jim", "Jack"))
mygraph <- graph_from_data_frame(d=mydata, directed=T)
plot(mygraph, vertex.label.dist=2)
I would like to get the same result than with:
g4 <- graph( c("John", "Jim", "Jim", "Jack", "John", "John"), isolates=c("Jesse") )
plot(g4, vertex.label.dist=2)
but working with two columns, from and to. How can I get the same result? When any of the "from" or "to" is NA then just plot the node without edges and without producing errors.