<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/tao-of-tidygraph-2/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://www.questionflow.org/2018/03/06/tao-of-tidygraph/"> QuestionFlow </a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p> Analysis of one interesting alliance graph within tidy network analysis framework.</p>
<div>
<h1>Prologue</h1>
<p>Quite some time ago I read the fantastic <a rel="nofollow" href="http://www.burns-stat.com/documents/books/tao-te-programming/" target="_blank">“Tao Te Programming”</a> book by <a rel="nofollow" href="http://www.burns-stat.com/" target="_blank">Patrick Burns</a>. You can know this author from his everlasting work <a rel="nofollow" href="http://www.burns-stat.com/documents/books/the-r-inferno/" target="_blank">“The R Inferno”</a>.</p>
<p>“Tao Te Programming” is a vision about what a good programming should be. It is written in [programming] language-agnostic fashion but mainly with R in mind. It is organized in 81 chapters with some distinctive feature: at the end of the most chapters there are lists of chapters-“allies” and chapters-“opponents” to the chapter in question. During the reading I was really interested in the properties of <a rel="nofollow" href="https://en.wikipedia.org/wiki/Graph_(discrete_mathematics)" target="_blank">graph</a> that is created with these connections.</p>
<p>From the other side of my life, I constantly hear about packages for tidy network analysis: <a rel="nofollow" href="https://github.com/thomasp85/tidygraph" target="_blank">tidygraph</a> and <a rel="nofollow" href="https://github.com/thomasp85/ggraph" target="_blank">ggraph</a>. Both created by “compulsive package developer” (not sure, where to put “great” in this description) <a rel="nofollow" href="https://www.data-imaginist.com/" target="_blank">Thomas Lin Pedersen</a>. They provide tidy tools for creating, manipulating and plotting network data. It happened, that I didn’t have an opportunity to work with them… until now.</p>
</div>
<div>
<h1>Overview</h1>
<p>This post is mainly about exploration of “Tao Te Programming” alliance graph using <code>tidygraph</code> and <code>ggraph</code>, with a few descriptions about those package functionality (for a thorough overview check out this <a rel="nofollow" href="https://www.rstudio.com/resources/videos/tidying-up-your-network-analysis-with-tidygraph-and-ggraph/" target="_blank">speach</a> by Thomas at rstudio::conf 2018). It will cover:</p>
<ul>
<li><strong>Creation</strong>, <strong>visualization</strong> and <strong>exploration</strong> of alliance graph.</li>
<li>Determination of “central programming advice” or <strong>“Why you should learn to dance the Debug 2-Step”</strong>.</li>
</ul>
<p>Data and code can be found in my <a rel="nofollow" href="https://github.com/echasnovski/taoteprog" target="_blank">taoteprog</a> repository. It is a project with R package structure which can be installed with <code>devtools::install_github(&quot;echasnovski/taoteprog&quot;)</code> (for easier data access). Public sharing of these data and results of this analysis is agreed with Mr. Burns by e-mail.</p>
<p>Setup:</p>
<pre><code>library(taoteprog)
library(tidyverse)
library(tidygraph)
library(ggraph)

set.seed(201803)</code></pre>
</div>
<div>
<h1>Alliance graph</h1>
<div>
<h2>Creation</h2>
<p>Alliance graph is a set of chapters-nodes which created based on “ally” and “opponent” connections. It is created using the following data from <code>taoteprog</code> (which I manually created while reading a book):</p>
<ul>
<li><code>ttp_chapters</code> – a <a rel="nofollow" href="http://tibble.tidyverse.org/" target="_blank">tibble</a> with chapter data (column <code>chapter</code> for its number and <code>name</code> for its name). The whole list of chapters can be found <a rel="nofollow" href="http://www.burns-stat.com/documents/books/tao-te-programming/table-of-contents/" target="_blank">here</a>.</li>
<li><code>ttp_edges</code> – a tibble with data about chapter connections. It has the following columns:
<ul>
<li><code>chapter1</code> for the chapter number at which list of connections is printed.</li>
<li><code>chapter2</code> for the number of connected chapter.</li>
<li><code>type</code> for connection type (either “ally” or “opponent”).</li>
</ul>
<p><strong>Note</strong> that connections between chapters are not symmetrical, i.e. one chapter can be an “ally” or “opponent” of the another but not the other way around.

<pre><code>ttp_raw &lt;- tbl_graph(nodes = ttp_chapters, edges = ttp_edges, directed = TRUE)
ttp_raw
## # A tbl_graph: 81 nodes and 124 edges
## #
## # A directed multigraph with 20 components
## #
## # Node Data: 81 x 2 (active)
##   chapter name                   
##     </code></pre></ul></div></div>