Book Image

Haskell Data Analysis cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis cookbook

By: Nishant Shukla

Overview of this book

Step-by-step recipes filled with practical code samples and engaging examples demonstrate Haskell in practice, and then the concepts behind the code. This book shows functional developers and analysts how to leverage their existing knowledge of Haskell specifically for high-quality data analysis. A good understanding of data sets and functional programming is assumed.
Table of Contents (14 chapters)
13
Index

Visualizing a graph network

Graphical networks of edges and nodes can be difficult to debug or comprehend, and thus, visualization helps tremendously. In this recipe, we will convert a graph data structure into an image of nodes and edges.

Getting ready

To use Graphviz, the graph visualization library, we must first install it on the machine. The official website of Graphviz contains the download and installation instructions (http://www.graphviz.org). On Debian-based operating systems, Graphviz can be installed using apt-get as follows:

$ sudo apt-get install graphviz-dev graphviz

Next, we need to install the Graphviz Haskell bindings from Cabal as follows:

$ cabal install graphviz

How to do it…

  1. Import the relevant libraries as follows:
    import Data.Text.Lazy (Text, empty, unpack)
    import Data.Graph.Inductive (Gr, mkGraph)
    import Data.GraphViz (GraphvizParams, nonClusteredParams, graphToDot)
    import Data.GraphViz.Printing (toDot, renderDot)
  2. Create a graph defined by identifying the pairs...