Search code examples
gephigraph-visualization

Import custom partition into Gephi


I was wondering if gephi supports importing a cluster file that has the community assignment of each node in a graph on a separate line (similar to the Pajek .clu format)? I am looking for a way to color the nodes belonging to the same community. In igraph (for R), I can import this file and set the vertex color attributes based on it. Was wondering if gephi had a similar feature?

I saw this answer here from over 5 years ago saying that it wasn't possible, was wondering if that had changed now?

Thanks!


Solution

  • The .clu file contains one line per node with the cluster number at least the example I see here. Gephi cannot import it directly but you can trick it to obtain the same result. Here are the steps I propose:

    1. Import your .net file with Gephi
    2. Go to Data Laboratory and sort your nodes according to the Id column, by clicking on the column name
    3. Create a new column called Cluster by pressing Add column the bottom of the screen. The default String type will do
    4. Click Export table, select only the fields Id and Cluster, and export the file somewhere
    5. Open the CSV file with e.g. Excel or LibreOffice
    6. Open your .clu file with a text editor, even Notepad will do
    7. Copy all the numbers in the file and paste them in the Cluster column of your CSV. Save your CSV
    8. Import the CSV back into Gephi, by clicking Import Spreadsheet and press ok through the next steps.

    At the end you should see your Cluster values having the same values as in the .clu file!

    Make sure that the same field delimiter is used throughout in steps 4. and 8. I would suggest to use ; as Excel directly understands it.

    You are welcome to report back if you are still having problems