block by bherr2 28f249148f38d99ada9185339e21f89d

Neo4J Database + GEPHI + Vega Lite Example

Full Screen

Neo4J Databases + GEPHI + Vega Lite Example

A Vega-Lite example that uses JSON data exported from Gephi: The Open Graph Viz Platform.

An example Neo4J database was copied from SPOKE. It was imported, queried and exported, converted, loaded into Gephi, and exported as a JSON Graph (File/Export/Graph file...). The data is embedded in the Vega-Lite spec (vis.vl.json) as two datasets: nodes and edges. The spec renders nodes and edges according to the color and size encodings created in Gephi. All attributes available to Gephi are available in the Vega-Lite spec for further customization as needed.

Specific steps for data generation are below.

1. Extract JSON data from Neo4J database


// Part Of Tree
MATCH (n:Anatomy)
MATCH (n2:Anatomy)
MATCH (n)-[rels:PARTOF_ApA]-(n2)
WITH collect(distinct n) as a, collect(distinct rels) as b
CALL apoc.export.json.data(a, b, "anatomy.json", {stream: true, writeNodeProperties: false})
YIELD file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data
RETURN file, source, format, nodes, relationships, properties, time, rows, batchSize, batches, done, data

2. Extract data for GEPHI


# Extract nodes from export
cat <(echo "id,identifier,label") <(jq -r 'select(.type == "node") | ([.id, .properties.identifier, .properties.name]) | @csv' import/anatomy.json) > nodes.csv

# Extract edges from export
cat <(echo "source,type,target") <(jq -r 'select(.type == "relationship") | ([.start.id, .label, .end.id]) | @csv' import/anatomy.json) > edges.csv

3. Layout data in GEPHI and export to JSON Graph

  1. Exported layout as a JSON Graph (File/Export/Graph file...) to graph.json

index.html

vis.vl.json