# The Art of Connecting the Dots with the Wolfram Language

Connect the dots. It was exciting to draw from number to number until the sudden discovery of a hidden cartoon. That was my inadvertent introduction to graph theory very early in school. Little did I know adults used the same concept to discover hidden patterns to solve problems, such as proving that a single crossing of seven Königsberg bridges to four land masses is not possible, but coloring a map distinctly with four colors is. These problems inspired the methods we know today as graph theory. And in honor of the work of late mathematician and connect-the-dot author Elwyn Berlekamp, we see how sophisticated this “child’s play” can be by examining the different styles and themes we can apply to graphs.

Graph theory has a history dating back to 1735, when the Königsberg bridge problem was proved to be not possible by Swiss mathematician Leonhard Euler. Today it touches us in many ways, from discovering the shortest route while on vacation to returning relevant links with a web search. Smooth traffic flow, efficient package delivery and reliable power grids utilize graph theory and affect our daily lives.

The Wolfram Language provides an extensive set of tools to reveal the underlying structures of a particular graph. Styling plays a significant role in the ability to analyze these graph structures easily. The `PlotTheme` family of themes, already used by the Wolfram Language’s visualizations and gauges, has found its way to the graph functions and provides a simple way to apply various styles.

As with any family, each member has its own unique personality. The personality of each theme was designed to help with the visual challenges that surface during graph analysis. Some themes work well locating paths in a complex graph, while others add visual excitement to an otherwise mundane graph.

## How Does PlotTheme Work?

`PlotTheme` sets a theme for Wolfram Language visualizations. A theme is a list of option values called by a single string name.

✕
CompleteGraph[5, PlotTheme -> "Web"] |

Included are the eight original base themes plus three feature themes found only in `Graph`: `"LargeGraph"`, `"ClassicLabeled"` and `"IndexLabeled"`.

Each theme automatically handles its own highlighting style.

## Which PlotTheme Should I Use?

`PlotTheme` does not overwhelm with an unlimited number of themes. Instead, each theme includes specific useful features.

For example, these features can help locate a path in a complex network:

Spice up a graph with different colors and shapes.

Locate a specific vertex with labels.

Produce artwork suitable for one-color printing.

Gratify an artistic side with color variety.

And of course, for the sentimental, the original styles remain available.

A `PlotTheme` combined with `GraphHighlightStyle` eases the task of finding that perfect style. As illustrated here, it helps the `"LargeGraph"` theme reveal a path in a complex graph:

## Literally Connect the Dots with Graph and PlotTheme

This section is for those who came to this blog expecting a function to connect the dots. The function utilizes `Graph` and `PlotTheme` and is included with the downloadable notebook of this blog.

✕
connectTheDots[CloudGet["https://wolfr.am/D4Xf2C4o"], PlotTheme -> "Minimal"] |

Set the `"ShowSolution"` option to `True` to see the result.

✕
connectTheDots[CloudGet["https://wolfr.am/D4Xf2C4o"], "ShowSolution" -> True] |

Other themes provide unique styling.

✕
connectTheDots[CloudGet["https://wolfr.am/D4Xf2C4o"], PlotTheme -> "Marketing"] |

Visually simplifying a problem with graph theory is a necessity in our world of growing complexity. Explore examples in the Wolfram Demonstrations Project to see what others have discovered. Visit the Graph Visualization and `PlotTheme` documentation pages to learn more.

Szabolcs, thanks for the suggestions. We will take them into consideration.

Hello Tim,

I use both Graph and HighlightGraph a lot, and it’s great to see that so much attention is given to making the styles look nice. I do love to use them. May I make a small suggestion? I would love to see GraphHighlightStyle -> “Thick” work better with all the plot themes. I use this highlight style the most, followed by DehighlightFade/DehighlightGray, which you showcase here. Speaking of that, it would be great to see DehighlightFade/DehighlightGray in the default auto-completion list for GraphHighlightStyle. After all, it seems these are the highlight styles you worked on the most!

I do love the styles you presented here, and I used many of them in the documentation of my IGraph/M package: http://szhorvat.net/mathematica/IGraphM Check out the PDF preview linked from that page.

Speaking of connecting dots, could we do it automatically? The concept of the relative neighbourhood graph was invented for this:

https://en.wikipedia.org/wiki/Relative_neighborhood_graph

IGraph/M implements it, as well its generalization, beta skeletons.

Try this:

dots = GraphEmbedding@connectTheDots[pandaImage];

Then this:

Manipulate[

IGLuneBetaSkeleton[dots, beta, PlotTheme -> “Web”],

{{beta, 1.5}, 1, 2}

]

Finally, while you didn’t show it here, there are a number of other very useful Graph-specific plot themes: the older GraphStyle settings. I use PlotTheme -> “ThickEdge” the most, especially when I need to colour the edges individually, and make their colours distinguishable. Colours are not easy to see on thin lines.

I forgot to include some code under the “Try this:” line, before the Manipulate.

IGRelativeNeighborhoodGraph[dots, PlotTheme -> “ThickEdge”]

I used the Wolfram Language to study percolation theory and the disassembly of biological virus shells. We were able to successfully predict in vitro experimental results on the disassembly of Hepatitis B Virus shells in the following (2) papers:

https://www.ncbi.nlm.nih.gov/pubmed/29714713

https://www.ncbi.nlm.nih.gov/pubmed/28795465

So Mathematica graph theory functionality may be used to study percolation theory.

An efficient function to determine the percolation thresholds of graphs would be a useful feature in future releases!

This would be of interest to a broad community, as there are a number of entries even on Wolfram MathWorld describing the broad applicability of percolation theory to various phenomena:

http://mathworld.wolfram.com/Percolation.html

http://mathworld.wolfram.com/PercolationThreshold.html

http://demonstrations.wolfram.com/PercolationOnASquareGrid/

Tim, I’d like to suggest that when you design these styles, also consider what graphs look like in small sizes. When the graphs are in a list, they are displayed in smaller size.

I find PlotTheme -> “Minimal” to produce very readable renderings at small sizes for undirected graphs. But directed graphs are practically unreadable because the arrowheads are too small.

Here’s an example:

Table[DirectedGraph[CompleteGraph[5], “Random”,

PlotTheme -> “Minimal”], {6}]

It would be useful if the arrowheads did not scale with the rest of the graph. This is already the case with the default style, and should be implementable for Minimal as well.

Szabolcs, thanks for the suggestion. Custom arrows scale with graph size but the size can be set manually using EdgeShapeFunction->GraphElementData[“ShortUnfilledArrow”, “ArrowSize”->.075]. We make design decisions based on a variety of graph sizes and densities but unfortunately not able to cover all cases. Manual adjustment covers these cases.