Easy Graph Visualization With Motif
Tags: tutorial, showdev, javascript, graphs
Published: 2021-07-28 14:16:22

Motif is a graph viz web app that simplifies analysis and exploration of rich graph datasets. 

Inspired by [kepler.gl](https://kepler.gl/), it makes visual discovery on graph datasets accessible to analysts, data scientists and managers.

It was created to make analysis and exploration of rich graph datasets with numerous node and edge properties easy. With a web interface, we make it easy to share results and analysis.

In this post, I will highlight the main features of Motif and do a walkthrough showing how we can visualize the Les Misérables dataset!

Feel free to try it out at https://demo.cylynx.io. If you like the project, give us a star at our [github repo](https://github.com/cylynx/motif.gl)!

## Features

### Import options

![csv import with motif](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qcr5v89tc6m321o65t4p.png)

Motif supports a variety of import options including CSV files (edge lists, or node-and-edge CSVs), JSON files (its native format), Neo4j and it also includes a jupyter notebook integration!

For more information on using Motif with jupyter notebooks, check out our post on [pymotif](https://medium.com/cylynx/introducing-pymotif-194c74faceae).

### Layouts and styling options

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/irrmdv6momsyy0o8ay9z.png)

A variety of layout options are available including Concentric, Radial, Grid, Sequential, Circular, Force-directed, and fixed coordinates.

You can also customize the colors and size of the nodes, as well as their labels. This includes mapping a particular node attribute to a color which automatically creates a legend! Similar styling options are available for edge properties as well.

### Filtering and search options

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6c0nh69doennc49x5ht9.png)

What's an explorer without filtering and search options? Like 
Kepler.gl, we provide a time filtering bar and different filtering options depending on the filtered property’s data type (string, number or date).

## Getting started with Motif

Simply head to [demo url](https://demo.cylynx.io) to get started and try out the various features outlined in the post.

## Importing Les Misérables

Let's take a look at how we can visualize the Les Misérables dataset. The Les Misérables dataset is included as a sample data so one can simply click on the "Sample Data" tab highlighted blue in the screenshot below, followed by the Les Misérables box, highlighted in green.

![motif import les mis](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ugezsaqgrtzwawxgy86l.png)

## Properties panel and tooltips

We can click on the "Select All" button in the node and edge properties panel to configure the attributes that we would like to see in the tooltips.

![motif properties panel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xkg3t6yvkswg6iovf7ca.png)

Double clicking a node and edge will show the relevant information in a tooltip.

## Configuring styles

The toolbar on the left provides a list of panels which comes in handy in data exploration and analysis. This includes a layers panel, a styles panel, a filter panel and a search panel. 

Let's switch from the layers panel to the styles panel by clicking on the palette icon 🎨.

![motif side panel](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/d1iidsah9heffl4yxlrg.png)

Feel free to play around with the numerous styling options available ✨

In the next section, I will show how we can create a pretty looking visualization that looks like this:

![Alt Text](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z7ofplzlm4bqmtr85ije.png)

### Use force-directed layout

[Force-directed layout](https://en.wikipedia.org/wiki/Force-directed_graph_drawing) is a good choice and tends to create aesthetically pleasing layouts. 

The math behind it is a little complicated and involves simulating the repulsive forces within an electrically charged system. Check out this [post](https://www.strong.io/blog/visualizing-graphs-coulomb-simulation) for more information.

Within Motif, the logic has been programmed and all that is required is to change the layout dropdown to force-directed!

![les mis force directed](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/grd03yq1tuyatsq595aq.png)

### Add a node label

Next, let's label the nodes with the characters’ names. In our dataset, the names are stored in the "id" field. Click on the 'label' dropdown box within 'node styles' and select the "id" property.

![les mis node label](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lcnhc52n4ia4zdd111rh.png)

### Color the nodes based on the ‘group’ field

The nodes have a "group" attribute that was generated by a clustering algorithm. Let's color the nodes based on their grouping.

To do that, we need to change the 'node color' from 'fixed' to 'legend', followed by choosing the "group" attribute as our variable of choice.

![les mis node legend](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/1vidpo3piu88r14mv4cp.png)

### Saving your masterpiece

That's it! You should have successfully replicated the example. 

To save or take a screenshot of your graph, head back to the layers panel and click on the camera button to take a screenshot, or the save button to download the file in JSON format.

![screenshot and save with motif](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/yrh1dvmmxynb0qpk8q0h.png)

Share the graph via email or slack, and the recipient can simply drag and drop the graph in the import modal to visualize it as you have created!

## Conclusion

I hope this post gives you a good introduction to Motif. Would love to see what you can create with the tool as well! If you have any feedback or comments, feel free to leave them here or at our [Github discussions page].(https://github.com/cylynx/motif.gl/discussions)

### Related content

[pymotif - Motif with jupyter notebook](https://medium.com/cylynx/introducing-pymotif-194c74faceae)
[motif with Neo4j (Nodes 2021, starts at 1:04:07)](https://neo4j.brand.live/c/2021nodes-visualization)
[Github repo](https://github.com/cylynx/motif.gl)
[more information](https://www.cylynx.io/motif)