briatte / ggnetwork

Geoms to plot networks with ggplot2
https://briatte.github.io/ggnetwork/
146 stars 28 forks source link

Can't handle networks with no edges #19

Closed mhairi closed 5 years ago

mhairi commented 7 years ago

If I make a network with only nodes, no edges

library(ggplot2)
library(network)
library(ggnetwork)

D <- matrix(c(1, 0, 0,
              0, 1, 0,
              0, 0, 1),
            nrow = 3,
            ncol = 3)

net <- network(D)

Then ggnetwork can't convert this to a dataframe:

> ggnetwork(net)
Error in xj[i, , drop = FALSE] : subscript out of bounds
mcanouil commented 7 years ago

Hi, I updated my pull request #20 to include a fix for this problem. It should works most of the time. I didn't account for any nodes/edges attributes.

mhairi commented 7 years ago

Thank you very much!

briatte commented 5 years ago

@mhairi First of all, all apologies for not answering earlier — and yes, thanks to @mcanouil, this problem is now solved.