简体   繁体   中英

Creating a graph from Neo4j Data in R

I have a dataset which consists of Users and Repositories, which I query against Neo4j

query = "
MATCH (user:User{name:'mattt'})-->(repo)
MATCH (repo)<--(allUsers:User)
RETURN repo.name, COLLECT(DISTINCT allUsers.name) AS users;
"
q = cypher(neo4j, query)

在此处输入图片说明

The relation is between the repo.name and a list of users point to it.

I am having trouble figuring out how to restructure the data to plot this in a graph.

I think you want to use a Cypher query that returns an edgelist, rather than having a list of all users that given user points to. Something like this:

MATCH (u:User)-->(r:Repo)
RETURN u.name AS from, r.name AS to;

Following along from this blog post about network visualization using RNeo4j:

query = "
MATCH (u:User)-->(r:Repo)
RETURN u.name AS from, r.name AS to;
"

edges = cypher(neo4j, query)

Then define a DataFrame for the nodes:

nodes = data.frame(id=unique(c(edges$from, edges$to)))
nodes$label = nodes$id

Then to visualize using the visNetwork libary :

visNetwork(nodes, edges)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM