briatte / ggnetwork

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

Error for 2-node, 1-tie network of class `igraph` #12

Closed instantkaffee closed 5 years ago

instantkaffee commented 7 years ago
g= igraph::random.graph.game(n = 2, p.or.m = 1)
ggnetwork::ggnetwork(g)

throughs in Version 0.5.1:

Error in if (nrow(edges[, 1:2]) > nrow(unique(edges[, 1:2]))) { : 
  argument is of length zero

I think g is a valid Input for ggnetwork. Any fix ?

instantkaffee commented 7 years ago

Hello @briatte , when do you think that a fix becomes available?

martinritchie commented 7 years ago

@instantkaffee I am running into the same problem, did you ever find a work around?

instantkaffee commented 7 years ago

@martinritchie No, I was hoping for a fix from @briatte

kgero commented 7 years ago

I'm also looking for a fix.

martinritchie commented 7 years ago

I think I have a fix, I will submit a pull request tomorrow.

instantkaffee commented 7 years ago

@martinritchie is your fix accepted?

martinritchie commented 7 years ago

Sorry for the slow reply. I noticed that there is already a pull requuest that fixes this issue. Have a look, it is quite easy to implement yourself whilst you wait for the pull to be approved.

briatte commented 5 years ago

This issue still looks alive, despite PR #20. Package might need PR #24 after all.

Interestingly, issue occurs only with igraph:

# remotes::install_github("briatte/ggnetwork")
library(ggnetwork)
#> Loading required package: ggplot2

# 2-node, 1-edge network
g <- igraph::random.graph.game(n = 2, p.or.m = 1)

# fails
ggnetwork(g)
#> Error in value[[3L]](cond): could not coerce object to a network: see ?ggnetwork for help
# fails
ggnetwork:::fortify.igraph(g) 
#> Error in if (nrow(edges[, 1:2]) > nrow(unique(edges[, 1:2]))) {: argument is of length zero

# ... but if converted to just a matrix
m <- as.matrix(igraph::as_adjacency_matrix(g))
# works
ggnetwork(m)
#>   x y  na.x vertex.names       xend       yend  na.y
#> 1 1 0 FALSE            1 1.00000000 0.00000000    NA
#> 2 0 1 FALSE            2 0.00000000 1.00000000    NA
#> 3 0 1 FALSE            2 0.98232233 0.01767767 FALSE
#> 4 1 0 FALSE            1 0.01767767 0.98232233 FALSE
# works
ggplot(ggnetwork(m), aes(x, y, xend = xend, yend = yend)) +
  geom_nodes() +
  geom_edges()


# ... same if converted to network
n <- network::network(m, directed = FALSE)
# works
ggnetwork(n)
#>    x y  na.x vertex.names xend yend  na.y
#> 1  0 1 FALSE            1    0    1    NA
#> 2  1 0 FALSE            2    1    0    NA
#> 21 1 0 FALSE            2    0    1 FALSE
# works
ggnetwork:::fortify.network(n)
#>    x y  na.x vertex.names xend yend  na.y
#> 1  0 1 FALSE            1    0    1    NA
#> 2  1 0 FALSE            2    1    0    NA
#> 21 1 0 FALSE            2    0    1 FALSE
# works
ggplot(ggnetwork(n), aes(x, y, xend = xend, yend = yend)) +
  geom_nodes() +
  geom_edges()

Created on 2019-07-27 by the reprex package (v0.3.0)

briatte commented 5 years ago

All apologies for the long wait one this issue… !

komalsrathi commented 5 years ago

Hi!

I just got this error with version 0.5.1. Was this resolved?

Thanks Komal

briatte commented 5 years ago

Hi @komalsrathi

Yes, that issue is solved, but in the development branch so far -- please reinstall the package from GitHub to solve the issue:

remotes:install_github("briatte/ggnetwork")

CRAN submission is late but will happen soon.