Skip to main content

Clustering nodes

Now, let's try to group nodes into clusters.


{
"data": [
{
"name": "data",
"url": "/data/blogs/network.csv",
"format": {"type": "csv"}
}
],

"networks": [
{
"name": "network",
"links": "data",
"directed": true,
"source_node": [ "id", "source" ],
"target_node": [ "id", "target" ],

"transform": [
{"type": "metric", "metric": "degree"}
{"type": "filterNodes", "expression": "datum.degree > 2 "}

After filtering, we perform an additional transform to apply Louvain clustering.


{"type": "cluster", "method": "louvain"}


]
}
],

"layouts": [
{
"name": "layout",
"network": "network",
"type": "d3-force"
}
],

Define a caegorical color scale


"scales": [
{
"name": "color",
"type": "linear",
"scheme": "category20",
"domain": [0, 20]
}
],



"vis": [
{
"entries": "network.links",
"layout": "layout",
"mark": {
"type": "linkpath",
"start": "source",
"end": "target"
}
},
{
"entries": "network.nodes",
"layout": "layout",
"mark": {
"type": "circle",
"area": 70,

Color each node based on the cluster number, using the color scale.


"fill": {"field": "louvain", "scale": "color"}


}
}
]
}