JohnCoene / sigmajs

Σ sigma.js for R
http://sigmajs.john-coene.com
Other
72 stars 7 forks source link

ERROR: Some vertex names in edge list are not listed in vertex data frame #22

Closed jwscot closed 2 years ago

jwscot commented 2 years ago

I am receiving the following error:

Error in igraph::graph_from_data_frame(edges, directed, nodes) : Some vertex names in edge list are not listed in vertex data frame

However when I run:

all(c(edg$source, edg$target) %in% nds$id)

It returns TRUE so why is it not working?

Nodes dataframe is columned:

id; label; x; y; size; color

Edges dataframe columned:

id; source; target

where source and target are the ids of nodes.

sigmajs() %>% # initialise
  sg_nodes(nds, id, label, x, y, size, color) %>% # add nodes
  sg_edges(edg, id, source, target) %>% # add edges
  sg_layout() %>%  # layout
  sg_neighbours() # show node neighbours on node click

Thanks in advance!

JohnCoene commented 2 years ago

I've had that error before but it was always accurate: my edges really contained nodes not present in the node table.set

Note that this is called in sg_layout but if you already have the positions (as you show x and y) then there is no need to use this function.

Could you share the dataset or a reproducible example? Also, have you tried running igraph::graph_from_data_frame(edges, FALSE, nodes)? Does it error?

jwscot commented 2 years ago

Thanks for the prompt response!

"Note that this is called in sg_layout but if you already have the positions (as you show x and y) then there is no need to use this function." - when I remove this, the error message no longer appears but no graph shows up in the RStudio viewer?

Running _igraph::graph_from_dataframe(edges, FALSE, nodes) produces the same initial error message.

Complete script attached below:

install.packages("sigmajs")

library(sigmajs)

edg <- read.csv('path/to/edges.csv') nds <- read.csv('path/to/nodes.csv')

sigmajs() %>% # initialise sg_nodes(nds, id, label, x, y, size, color) %>% # add nodes sg_edges(edg, id, source, target) %>% # add edges sg_layout() %>% # layout sg_neighbours() # show node neighbours on node click

[DATA REMOVED]

jwscot commented 2 years ago

Any ideas?

Additionally, please could you tell me how to export my network so that in can be viewed on a website?

jwscot commented 2 years ago

Please don't worry about these questions - I have found ways to workaround them! I won't bother to explain them as they aren't solutions, per sae; i.e. I have created the graph elsewhere, saved as a .gexf and then imported.