Hive Plots using R and Cytoscape

I found out about HivePlots this past summer, and although I thought they looked incredibly
useful and awesome, I didn't have a personal use for them at the time, and therefore put off doing anything with them.
That recently changed when I encountered some particularly nasty hairballs of force-directed graphs. Unfortunately, the
HiveR package does not create interactive hiveplots (at least for 2D), and that is particularly important for me. I don't necessarily want to be able to compare networks (one of the selling points made by Martin Krzywinski), but I do want to be able to explore the networks that I create. For
that reason I have been a big fan of the RCytoscapeBioconductor package since I encountered it, as it allows me to easily create graphs in R, and then interactively and programmatically explore them in Cytoscape

So I decided last week to see how hard it would be to generate a hive plot that could be visualized and interacted with in
Cytoscape. For this example I'm going to use the data in the HiveR package, and actually use the structures already
encoded, because they are useful.

Process Data

So here we have the data. The nodes is a data frame with the id, a label describing the node, which axis the node
belongs on, and its radius, or how far out on the axis the node should be, as well as a size. These are all modifiable
attributes that can be changed depending on how one wants to map different pieces of data. This of course is the beauty of
hive plots, because they result in networks that are dependent on attributes that the user decides on.

In this case, we have a transcription factor regulation network. I am going to point you to the previous links as to why
a normal force-directed network diagram is not really that informative for these types of networks. I'm not out to
convince you that HivePlots are useful, if you don't get it from the publication and examples, then you should stop
here. This is more about how to do some calculations to lay them out and work with them in Cytoscape.

Bryan has implemented some nice functions to work with this type of network and perform simple calculations to assign
axes and locations based on properties of the nodes. For example, it is easy to locate nodes on an axis based on the total number of edges.

And then to assign the axis to be plotted on based on the whether edges are incoming (sink), outgoing (source), or both (manager). These are the types of decisions that influence whether you get anything insightful or useful out of a
HivePlot, and changing these options can of course change the conclusions you will make on a particular network.

Calculate Node Locations

In this case we have three axes, so we are going to calculate the axes locations as 0, 120, and 240 degrees. However, we
need to use radians, because the conversion from spherical to cartesian coordinates involves using cosine and sine, which
in R is based on radians.

We also want to put information we know about the nodes and edges in the graph, so that we can modify colors and stuff
based on those attributes. For example, in this case we might want to modify the node color based on the axis it is on.
Using attributes means we are not stuck using the colors that we previously assigned.

This looks pretty awesome! And I can zoom in on it, and examine it, and look at various properties! And I get the full
scripting power of R if I want to do anything else with, such as select sets of edges or nodes and then query who is
attached to whom.

Disadvantages

We don't get the arced edges. This kind of sucks, but from what little I have done with these, that actually is not that
big a deal. Would be cool if there was a way to do that, however. I do see that the web version of Cytoscape does allow
you to set a value for how much “arcness” you want on an edge.

This does mean that any plot with only two axes would need special consideration. Instead of doing two axes end to end
(using 180 deg), it might be better to make them parallel to each other.

With more than three axes, line crossings may become a problem. In that case, it may be worth looking to see if there are
ways to tell Cytoscape in what order to draw edges. I don't know if that is possible using the XMLRPC pipe that is used
by RCy.

RCy Tip

If you want to know how the image will look when saving a network to an image, use showGraphicsDetails(obj, TRUE).

Other Visualizations

Of course, I had just wrapped my head around using HivePlots in my own work, when I encountered ISBs BioFabric. Given how they are representing this, could we find a way to draw this in Cytoscape??