<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/network-analysis-of-game-of-thrones-family-ties/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://shiring.github.io/networks/2017/05/15/got_final"> Shirin's playgRound</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<p>In this post, I am exploring network analysis techniques in a family network of major characters from Game of Thrones.</p>
<p>Not surprisingly, we learn that House Stark (specifically Ned and Sansa) and House Lannister (especially Tyrion) are the most important family connections in Game of Thrones; they also connect many of the storylines and are central parts of the narrative.</p>
<p></p>
<h2>What is a network?</h2>
<p>A network in this context is a graph of interconnected nodes/vertices. Nodes can e.g. be people in a social network, genes in a co-expression network, etc. Nodes are connected via ties/edges.</p>
<p></p>
<h2>What can network analysis tell us?</h2>
<p>Network analysis can e.g. be used to explore relationships in social or professional networks. In such cases, we would typically ask questions like:</p>
<ul>
<li>How many connections does each person have?</li>
<li>Who is the most connected (i.e. influential or “important”) person?</li>
<li>Are there clusters of tightly connected people?</li>
<li>Are there a few key players that connect clusters of people?</li>
<li>etc.</li>
</ul>
<p>These answers can give us a lot of information about the patterns of how people interact.</p>
<p></p>
<h2>The Game of Thrones character network</h2>
<p>The basis for this network is <a target="_blank" rel="nofollow" href="https://www.kaggle.com/mylesoneill/game-of-thrones">Kaggle’s Game of Throne dataset (character-deaths.csv)</a>. Because most family relationships were missing in that dataset, I added the missing information in part by hand (based on <a target="_blank" rel="nofollow" href="http://awoiaf.westeros.org/">A Wiki of Ice and Fire</a>) and by scraping information from <a target="_blank" rel="nofollow" href="http://gameofthrones.wikia.com/">the Game of Thrones wiki</a>. You can find the full code for how I generated the network <a target="_blank" rel="nofollow" href="https://github.com/ShirinG/blog_posts_prep/blob/master/GoT/got.Rmd">on my Github page</a>.</p>
<div>
<pre><code><span>library</span><span>(</span><span>tidyverse</span><span>)</span><span>
</span><span>library</span><span>(</span><span>igraph</span><span>)</span><span>
</span><span>library</span><span>(</span><span>statnet</span><span>)</span><span>
</span></code></pre>
</div>
<div>
<pre><code><span>load</span><span>(</span><span>&quot;union_edges.RData&quot;</span><span>)</span><span>
</span><span>load</span><span>(</span><span>&quot;union_characters.RData&quot;</span><span>)</span><span>
</span></code></pre>
</div>
<p></p>
<p>I am using <strong>igraph</strong> to plot the initial network. To do so, I first create the graph from the edge- and node-table. An edge-table contains source and target nodes in the first two columns and optionally additional columns with edge attributes. Here, I have the type of interaction (mother, father or spouse), the color and line-type I want to assign to each edge.</p>
<p>Because the books and the TV series differ slightly, I have introduced edges that are only supported or hinted at by the TV series and are not part of the original narrative in the books. These edges are marked by being dotted instead of solid. An additional color for edges with unspecified parental origin are introduced as well. Originally, these served for interactions that were extracted from character names (i.e. characters that ended with “… son/daughter of …”) and could either mean mother or father. Now, they show unclear parentage or cases where there are a biological and a de facto father, as in the case of Jon Snow.</p>
<div>
<pre><code><span>head</span><span>(</span><span>union_edges</span><span>)</span><span>
</span></code></pre>
</div>
<div>
<pre><code>##               source            target   type   color   lty
## 1         Lysa Arryn      Robert Arryn mother #7570B3 solid
## 2       Jasper Arryn        Alys Arryn father #1B9E77 solid
## 3       Jasper Arryn         Jon Arryn father #1B9E77 solid
## 4          Jon Arryn      Robert Arryn father #1B9E77 solid
## 110 Cersei Lannister  Tommen Baratheon mother #7570B3 solid
## 210 Cersei Lannister Joffrey Baratheon mother #7570B3 solid
</code></pre>
</div>
<p>The nodetable contains one row for each character that is either a source or a target in the edgetable. We can give any number and type of node attributes. Here, I chose the followin columns from the original Kaggle dataset: gender/male (male = 1, female = 0), house (as the house each character was born into) and popularity. House2 was meant to assign a color to only the major houses. Shape represents the gender.</p>
<div>
<pre><code><span>head</span><span>(</span><span>union_characters</span><span>)</span><span>
</span></code></pre>
</div>
<div>
<pre><code>##            name male culture          house popularity      house2   color  shape
## 1    Alys Arryn    0    </code></pre></div>