briatte / ggnetwork

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

ggnetwork function Error in rbind(deparse.level, ...) #78

Open Prenauer opened 3 days ago

Prenauer commented 3 days ago

I had trouble using the ggnetwork() function and got the following error: Error in rbind(deparse.level, ...) : numbers of columns of arguments do not match

I looked into the code and found that format_fortify() included some code that doesn't seem to work:

edges <- merge(nodes, edges, by = c("x", "y"), all = TRUE)

This strategy might not work for a lot of situations, in which the edges data.frame already has columns with the same names as those with the nodes data.frame.

I fixed this changing the code to below

edges <- merge(nodes[, c("x", "y", setdiff(names(nodes), 
            names(edges)))], edges, by = c("x", "y"), all = TRUE)

This way, it doesn't matter what columns were previously present in edges and nodes.

Hope this helps.

briatte commented 1 day ago

Hi @Prenauer

Thanks for this. Would you mind submitting a PR?

Also, to be clear, in case of a name conflict between identically-named nodes and edges attributes, your solution drops columns on the nodes side, right? We might want to do the opposite, or even rename the edge ones by appending *_edges, for instance.