briatte / ggnetwork

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

Error when only one edge found #18

Closed trinker closed 5 years ago

trinker commented 7 years ago

Added , drop = FALSE to line 142 of file fortify-network.R:

nrow(edges[, 1:2, drop = FALSE]) > nrow(unique(edges[, 1:2, drop = FALSE]))

This prevents the matrix turning into a vector in the edge case when only a single edge is found.

For example, this failed previously but will work now:

library(igraph)
library(ggnetwork)

mat <- structure(c(0, 0, 0, 0.0930232558139535, 0, 0, 0, 0, 0, 0, 0, 
1, 0.0930232558139535, 0, 1, 0), .Dim = c(4L, 4L), .Dimnames = list(
    c("response_cries", "back_channels", "summons", "justification"
    ), c("response_cries", "back_channels", "summons", "justification"
    )))

graph <- igraph::graph.adjacency(mat, weighted=TRUE, mode="lower")
igraph::E(graph)$width  <- igraph::E(graph)$weight * 5
net <- igraph::as.undirected(igraph::delete.edges(graph, igraph::E(graph)[weight < .1]))
plot(net)
idat <- try(ggnetwork::ggnetwork(net), TRUE)
idat
trinker commented 7 years ago

I have a dependency on this package that I'd like to push to CRAN soon. What is your expected timeline for this version to go to CRAN?

I cleaned up a few errors/warnings/notes I could do quickly. I see an error left in the tests that needs to be addressed.

trinker commented 7 years ago

@briatte Do you have timeline to make changes and push to CRAN?

mcanouil commented 7 years ago

I didn't see at first your fix, so it is also included in my pull request with change in argument names ("color" to "colour") to be consistent with ggrepel/ggplot2 at the same time. ( #20)

briatte commented 5 years ago

Closing PR since PR #18 solves this too, with again all apologies for doing this only now… In truth, your termco package is almost certainly better off with ggraph (except if you need minimal dependencies, which is, I believe, the only thing that ggnetwork has that ggraph does not).