<!DOCTYPE html>
<!-- Generated by pkgdown: do not edit by hand --><html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<title>Introduction to vosonSML • vosonSML</title>
<!-- favicons --><link rel="icon" type="image/png" sizes="16x16" href="../favicon-16x16.png">
<link rel="icon" type="image/png" sizes="32x32" href="../favicon-32x32.png">
<link rel="apple-touch-icon" type="image/png" sizes="180x180" href="../apple-touch-icon.png">
<link rel="apple-touch-icon" type="image/png" sizes="120x120" href="../apple-touch-icon-120x120.png">
<link rel="apple-touch-icon" type="image/png" sizes="76x76" href="../apple-touch-icon-76x76.png">
<link rel="apple-touch-icon" type="image/png" sizes="60x60" href="../apple-touch-icon-60x60.png">
<script src="../lightswitch.js"></script><script src="../deps/jquery-3.6.0/jquery-3.6.0.min.js"></script><meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<link href="../deps/bootstrap-5.3.1/bootstrap.min.css" rel="stylesheet">
<script src="../deps/bootstrap-5.3.1/bootstrap.bundle.min.js"></script><link href="../deps/font-awesome-6.4.2/css/all.min.css" rel="stylesheet">
<link href="../deps/font-awesome-6.4.2/css/v4-shims.min.css" rel="stylesheet">
<script src="../deps/headroom-0.11.0/headroom.min.js"></script><script src="../deps/headroom-0.11.0/jQuery.headroom.min.js"></script><script src="../deps/bootstrap-toc-1.0.1/bootstrap-toc.min.js"></script><script src="../deps/clipboard.js-2.0.11/clipboard.min.js"></script><script src="../deps/search-1.0.0/autocomplete.jquery.min.js"></script><script src="../deps/search-1.0.0/fuse.min.js"></script><script src="../deps/search-1.0.0/mark.min.js"></script><!-- pkgdown --><script src="../pkgdown.js"></script><link href="../extra.css" rel="stylesheet">
<meta property="og:title" content="Introduction to vosonSML">
</head>
<body>
    <a href="#main" class="visually-hidden-focusable">Skip to contents</a>


    <nav class="navbar navbar-expand-lg fixed-top " aria-label="Site navigation"><div class="container">

    <a class="navbar-brand me-2" href="../index.html">vosonSML</a>

    <small class="nav-text text-muted me-auto" data-bs-toggle="tooltip" data-bs-placement="bottom" title="">0.35.0</small>


    <button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbar" aria-controls="navbar" aria-expanded="false" aria-label="Toggle navigation">
      <span class="navbar-toggler-icon"></span>
    </button>

    <div id="navbar" class="collapse navbar-collapse ms-3">
      <ul class="navbar-nav me-auto">
<li class="nav-item"><a class="nav-link" href="../index.html"><span class="fa fa-home fa-lg"></span></a></li>
<li class="nav-item"><a class="nav-link" href="../news/index.html"><span class="fa fa-newspaper"></span> Changelog</a></li>
<li class="nav-item"><a class="nav-link" href="../reference/index.html"><span class="fa fa-cubes fa-lg"></span> Reference</a></li>
<li class="active nav-item dropdown">
  <button class="nav-link dropdown-toggle" type="button" id="dropdown-articles" data-bs-toggle="dropdown" aria-expanded="false" aria-haspopup="true"><span class="fa fa-book"></span> Articles</button>
  <ul class="dropdown-menu" aria-labelledby="dropdown-articles">
<li><a class="dropdown-item" href="../articles/Intro-to-vosonSML.html"><span class="fa far fa-file-alt"></span> Introduction to vosonSML</a></li>
    <li><a class="external-link dropdown-item" href="https://vosonlab.github.io/posts/2021-03-15-hyperlink-networks-with-vosonsml"><span class="fa far fa-file-alt"></span> Hyperlink Networks with vosonSML</a></li>
    <li><a class="external-link dropdown-item" href="https://vosonlab.github.io/posts/2022-06-05-egocentric-networks-from-twitter-timelines"><span class="fa far fa-file-alt"></span> Egocentric Networks from Twitter timelines</a></li>
    <li><a class="external-link dropdown-item" href="https://vosonlab.github.io/posts/2021-10-01-testing-bot-status-of-twitter-users"><span class="fa far fa-file-alt"></span> Testing the bot status of users in Twitter networks collected via vosonSML</a></li>
  </ul>
</li>
      </ul>
<ul class="navbar-nav">
<li class="nav-item"><a class="external-link nav-link" href="http://vosonlab.net/"><span class="fa fa-flask fa-lg"></span></a></li>
<li class="nav-item"><a class="external-link nav-link" href="https://twitter.com/vosonlab"><span class="fa fab fa-twitter-square fa-lg"></span></a></li>
<li class="nav-item"><a class="external-link nav-link" href="https://github.com/vosonlab/vosonSML"><span class="fa fab fa-github fa-lg"></span></a></li>
      </ul>
</div>


  </div>
</nav><div class="container template-article">




<div class="row">
  <main id="main" class="col-md-9"><div class="page-header">

      <h1>Introduction to vosonSML</h1>
            <h3 data-toc-skip class="subtitle">VOSON Lab, Australian
National University</h3>
                        <h4 data-toc-skip class="author">Robert Ackland,
Bryan Gertzel, Francisca Borquez</h4>
            
            <h4 data-toc-skip class="date">21 July, 2024</h4>
      
      <small class="dont-index">Source: <a href="https://github.com/vosonlab/vosonSML/blob/HEAD/vignettes/Intro-to-vosonSML.Rmd" class="external-link"><code>vignettes/Intro-to-vosonSML.Rmd</code></a></small>
      <div class="d-none name"><code>Intro-to-vosonSML.Rmd</code></div>
    </div>

    
    
<p>The following guide provides an introduction to using <a href="https://github.com/vosonlab/vosonSML" class="external-link">vosonSML</a>, which is
available both on GitHub and <a href="https://cran.r-project.org/package=vosonSML" class="external-link">CRAN</a>. More
resources are available on the VOSON Lab website (<a href="http://vosonlab.net/socialmedialab" class="external-link">vosonSML</a> and <a href="http://vosonlab.net/resources_training" class="external-link">training materials</a>).
For a full list of functions, please refer to the <a href="https://vosonlab.github.io/vosonSML/reference/index.html">reference
page</a>. The companion package to <code>vosonSML</code> is <a href="https://github.com/vosonlab/VOSONDash" class="external-link">VOSON Dashboard</a>, which
provides an R/Shiny graphical user interface for data collection (via
<code>vosonSML</code>), network and text analysis.</p>
<p>To use <code>vosonSML</code>, you first need to load it into the
session:</p>
<div class="sourceCode" id="cb1"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://vosonlab.github.io/vosonSML">vosonSML</a></span><span class="op">)</span></span></code></pre></div>
<p>There are three steps involved in data collection and network
creation using <code>vosonSML</code>. These are:</p>
<ol style="list-style-type: decimal">
<li>
<em>Authenticate</em> with the platform API, using the function
<code><a href="../reference/Authenticate.html">Authenticate()</a></code>
</li>
<li>
<em>Collect</em> data from the API and store it for later use, using
<code><a href="../reference/Collect.html">Collect()</a></code>
</li>
<li>
<em>Create</em> networks from the collected data, using
<code><a href="../reference/Create.html">Create()</a></code> and <code><a href="../reference/Graph.html">Graph()</a></code>
</li>
</ol>
<div class="section level2">
<h2 id="twitter">Twitter<a class="anchor" aria-label="anchor" href="#twitter"></a>
</h2>
<div class="section level3">
<h3 id="authenticating-with-the-twitter-api">Authenticating with the Twitter API<a class="anchor" aria-label="anchor" href="#authenticating-with-the-twitter-api"></a>
</h3>
<p>The first step is to authorise access to the Twitter API. This
requires completion of an application and approval for <a href="https://developer.twitter.com/en/apply-for-access" class="external-link">Twitter
Developer access</a>. Once the application has been approved then the
Twitter Developer Portal will become available and a new “Standalone
App” can be created. Creation of an app allows keys to be generated
through which software such as <code>vosonSML</code> can access and
collect data from the Twitter v1.1 API.</p>
<p><code>vosonSML</code> is only concerned with reading Twitter data, so
a full range of typical third-party app <code>user</code> or
<code>bot</code> functions are not required. The ideal type of
authentication for read-only access is <code>application</code> based
authentication with a <code>bearer</code> token that can be generated
and found under the <code>Authentication Tokens</code> section of a
developers app project on the Developer Portal. This type of token has
higher tweet collection rate-limits than other methods but less
permissions. With a <code>bearer</code> token the Twitter authentication
object can be set as follows:</p>
<div class="sourceCode" id="cb2"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">twitterAuth</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Authenticate.html">Authenticate</a></span><span class="op">(</span><span class="st">"twitter"</span>, bearerToken <span class="op">=</span> <span class="st">"xxxxxxxxxxxx"</span><span class="op">)</span></span></code></pre></div>
<p>A <code>developer</code> access token can also be created by using
all of the developer keys generated for an app. This type of access is
suited to automated software such as <code>bots</code> that are required
to undertake a range of read and write Twitter activities. A
<code>developer</code> access token is not required for
<code>vosonSML</code> but can be used if desired, it will however have
lower rate-limits than the <code>bearer</code> token:</p>
<div class="sourceCode" id="cb3"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">twitterAuth</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Authenticate.html">Authenticate</a></span><span class="op">(</span></span>
<span>  <span class="st">"twitter"</span>,</span>
<span>  appName <span class="op">=</span> <span class="st">"My App"</span>,</span>
<span>  apiKey <span class="op">=</span> <span class="st">"xxxxxxxx"</span>,</span>
<span>  apiSecret <span class="op">=</span> <span class="st">"xxxxxxxx"</span>,</span>
<span>  accessToken <span class="op">=</span> <span class="st">"xxxxxxxx"</span>,</span>
<span>  accessTokenSecret <span class="op">=</span> <span class="st">"xxxxxxxx"</span></span>
<span><span class="op">)</span></span></code></pre></div>
<p>There is also a <code>user</code> based access method available in
which a Twitter user can permit an app to access the API on their
behalf. This is the method third-party Twitter clients use to allow
users to perform Twitter functions such as posting tweets with their
software. When authorizing the software to their account the user will
be informed of the scope of permissions they are granting to the app.
This method has the advantage of per-user rather than application
rate-limits. This method is currently only available to be used with
<code>vosonSML</code> if the user has access to an app
<code>API key</code> and <code>API secret</code>:</p>
<div class="sourceCode" id="cb4"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">twitterAuth</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Authenticate.html">Authenticate</a></span><span class="op">(</span></span>
<span>  <span class="st">"twitter"</span>,</span>
<span>  appName <span class="op">=</span> <span class="st">"An App"</span>,</span>
<span>  apiKey <span class="op">=</span> <span class="st">"xxxxxxxxxxxx"</span>,</span>
<span>  apiSecret <span class="op">=</span> <span class="st">"xxxxxxxxxxxx"</span></span>
<span><span class="op">)</span></span></code></pre></div>
<p>In all cases, Twitter authentication creates an authentication object
with access token that can be re-used in the future by saving it to
disk:</p>
<div class="sourceCode" id="cb5"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">saveRDS</a></span><span class="op">(</span><span class="va">twitterAuth</span>, file <span class="op">=</span> <span class="st">"twitter_auth"</span><span class="op">)</span></span></code></pre></div>
<p>The following loads into the current session a previously-created
authentication object:</p>
<div class="sourceCode" id="cb6"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">twitterAuth</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">readRDS</a></span><span class="op">(</span><span class="st">"twitter_auth"</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level3">
<h3 id="collecting-data-from-twitter">Collecting Data from Twitter<a class="anchor" aria-label="anchor" href="#collecting-data-from-twitter"></a>
</h3>
<p>The syntax for collecting Twitter data follow <a href="https://developer.twitter.com/en/docs/twitter-api/tweets/search/integrate/build-a-query" class="external-link">Twitter’s
rules and filtering documentation</a>. It is possible to collect tweets
including particular terms (e.g. hashtags), and boolean searches (see <a href="https://developer.twitter.com/en/docs/twitter-api/v1/rules-and-filtering/search-operators" class="external-link">standard
search operators</a>) are also possible. The collection may be filtered
by, for example, type of Twitter activity (e.g. to include retweets
only), number of collected tweets, language of tweet. As an example, the
following collects 1000 recent tweets containing the ‘#auspol’ hashtag
(a prominent hashtag for Australian politics), with retweets not being
collected.</p>
<div class="sourceCode" id="cb7"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">twitterData</span> <span class="op">&lt;-</span> <span class="va">twitterAuth</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu"><a href="../reference/Collect.html">Collect</a></span><span class="op">(</span></span>
<span>    searchTerm <span class="op">=</span> <span class="st">"#auspol"</span>,</span>
<span>    numTweets <span class="op">=</span> <span class="fl">1000</span>,</span>
<span>    includeRetweets <span class="op">=</span> <span class="cn">FALSE</span>,</span>
<span>    writeToFile <span class="op">=</span> <span class="cn">TRUE</span>,</span>
<span>    verbose <span class="op">=</span> <span class="cn">TRUE</span></span>
<span>  <span class="op">)</span></span></code></pre></div>
<p>The <code><a href="../reference/Collect.html">Collect()</a></code> function takes the following arguments
(when used for collecting Twitter data): <code>credential</code> (object
generated from <code><a href="../reference/Authenticate.html">Authenticate()</a></code> with class name
“twitter”(above we pass this via the pipe), <code>searchTerm</code>
(character string that specifies a Twitter search term),
<code>searchType</code> (character string indicating how to filter
returned tweets with options ‘recent’, ‘mixed’ or ‘popular’; default
type is ‘recent’), <code>numTweets</code> (numeric vector that specifies
how many tweets to be collected; default is 100),
<code>includeRetweets</code> (whether the search should filter out
retweets or not; default is TRUE), <code>retryOnRateLimit</code>
(whether to automatically pause collection when the Twitter API rate
limit is reached, and then restart; default is FALSE.),
<code>writeToFile</code> (whether to write the returned dataframe to
disk as an <code>.rds</code> file; default is FALSE), and
<code>verbose</code> (whether to output information about the data
collection; default is FALSE).</p>
<p>The <code><a href="../reference/Collect.html">Collect()</a></code> function returns a tibble (an enhanced
dataframe which has features that can make working with the data
easier). We can view the data we just collected (the following has been
modified to anonymise the data):</p>
<div class="sourceCode" id="cb8"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb8-1"><a href="#cb8-1" tabindex="-1"></a><span class="sc">&gt;</span> twitterData<span class="sc">$</span>tweets</span>
<span id="cb8-2"><a href="#cb8-2" tabindex="-1"></a><span class="co"># A tibble: 999 x 90</span></span>
<span id="cb8-3"><a href="#cb8-3" tabindex="-1"></a>   user_id status_id created_at          screen_name text  source</span>
<span id="cb8-4"><a href="#cb8-4" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>   <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>dttm<span class="sc">&gt;</span>              <span class="er">&lt;</span>chr<span class="sc">&gt;</span>       <span class="er">&lt;</span>chr<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb8-5"><a href="#cb8-5" tabindex="-1"></a> <span class="dv">1</span> xxxxxx… xxxxxxxx… <span class="dv">2020-01-09</span> <span class="dv">12</span><span class="sc">:</span><span class="dv">02</span><span class="sc">:</span><span class="dv">13</span> xxxx        <span class="st">"htt… Twitt…</span></span>
<span id="cb8-6"><a href="#cb8-6" tabindex="-1"></a><span class="st"> 2 xxxxxx… xxxxxxxx… 2020-01-09 12:01:32 xxxxxxxxx   "</span>Fir… Twitt…</span>
<span id="cb8-7"><a href="#cb8-7" tabindex="-1"></a> <span class="dv">3</span> xxxxxx… xxxxxxxx… <span class="dv">2020-01-09</span> <span class="dv">12</span><span class="sc">:</span><span class="dv">00</span><span class="sc">:</span><span class="dv">44</span> xxxxxxxxxxx <span class="st">"Ser… Twitt…</span></span>
<span id="cb8-8"><a href="#cb8-8" tabindex="-1"></a><span class="st"> [snip]</span></span>
<span id="cb8-9"><a href="#cb8-9" tabindex="-1"></a><span class="st"> … with 989 more rows, and 84 more variables: display_text_width &lt;dbl&gt;,</span></span>
<span id="cb8-10"><a href="#cb8-10" tabindex="-1"></a><span class="st">...</span></span></code></pre></div>
<div class="section level4">
<h4 id="importing-twitter-data">Importing Twitter Data<a class="anchor" aria-label="anchor" href="#importing-twitter-data"></a>
</h4>
<p>If you are reading a previously saved <code>writeToFile</code>
Twitter dataframe from disk, you simply need to use the
<code>readRDS</code> function:</p>
<div class="sourceCode" id="cb9"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">twitterData</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">readRDS</a></span><span class="op">(</span><span class="st">"2020-09-26_095354-TwitterData.rds"</span><span class="op">)</span></span></code></pre></div>
<p>As <code>vosonSML</code> uses <code>rtweet</code> for data collection
you can also import <code>rtweet</code> tweet data from dataframe or
<code>.RDS</code> file using <code>ImportRtweet()</code>:</p>
<div class="sourceCode" id="cb10"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># from dataframe</span></span>
<span><span class="va">tweets</span> <span class="op">&lt;-</span> <span class="fu">rtweet</span><span class="fu">::</span><span class="fu"><a href="https://docs.ropensci.org/rtweet/reference/search_tweets.html" class="external-link">search_tweets</a></span><span class="op">(</span><span class="st">"#auspol"</span>, n <span class="op">=</span> <span class="fl">100</span><span class="op">)</span></span>
<span><span class="va">twitterData</span> <span class="op">&lt;-</span> <span class="va">tweets</span> <span class="op">|&gt;</span> <span class="fu">ImportRtweet</span><span class="op">(</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># or from file</span></span>
<span><span class="va">twitterData</span> <span class="op">&lt;-</span> <span class="fu">ImportRtweet</span><span class="op">(</span><span class="st">"rtweet_search_n100.rds"</span><span class="op">)</span></span></code></pre></div>
</div>
</div>
<div class="section level3">
<h3 id="creating-twitter-networks">Creating Twitter Networks<a class="anchor" aria-label="anchor" href="#creating-twitter-networks"></a>
</h3>
<p>It is currently possible to create four types of networks using
Twitter data: (1) <em>actor network</em>; (2) <em>activity network</em>;
(3) <em>2-mode network</em> and (4) <em>semantic network</em>.</p>
<div class="section level4">
<h4 id="actor-network">Actor Network<a class="anchor" aria-label="anchor" href="#actor-network"></a>
</h4>
<p>In the Twitter <em>actor network</em>, nodes are users who have
either tweeted using the target search terms (#auspol in the above
example) or else are mentioned or replied to in tweets featuring the
search terms. Edges represent interactions between Twitter users, and an
edge attribute indicates whether the interaction is a mention, reply,
retweet, quoted retweet or self-loop. Self-loop edges are created in two
situations: (1) a user authors a tweet and mentions or replies to
themself; (2) a user authors a tweet containing the search term, but
does not mention or reply to any other user in that tweet.</p>
<div class="sourceCode" id="cb11"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">actorNetwork</span> <span class="op">&lt;-</span> <span class="va">twitterData</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"actor"</span>, writeToFile <span class="op">=</span> <span class="cn">TRUE</span>, verbose <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span>
<span></span>
<span><span class="va">actorGraph</span> <span class="op">&lt;-</span> <span class="va">actorNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span>writeToFile <span class="op">=</span> <span class="cn">TRUE</span>, verbose <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p><code>Create("actor")</code> returns a named list containing two
dataframes named “nodes” and “edges” (the following has been modified to
preserve anonymity):</p>
<div class="sourceCode" id="cb12"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb12-1"><a href="#cb12-1" tabindex="-1"></a><span class="sc">&gt;</span> actorNetwork</span>
<span id="cb12-2"><a href="#cb12-2" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb12-3"><a href="#cb12-3" tabindex="-1"></a><span class="co"># A tibble: 1,725 x 5</span></span>
<span id="cb12-4"><a href="#cb12-4" tabindex="-1"></a>   from             to              edge_type timestamp         status_id</span>
<span id="cb12-5"><a href="#cb12-5" tabindex="-1"></a>   <span class="sc">&lt;</span>fct<span class="sc">&gt;</span>            <span class="er">&lt;</span>fct<span class="sc">&gt;</span>           <span class="er">&lt;</span>fct<span class="sc">&gt;</span>     <span class="er">&lt;</span>fct<span class="sc">&gt;</span>             <span class="er">&lt;</span>fct<span class="sc">&gt;</span></span>
<span id="cb12-6"><a href="#cb12-6" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxx         xxxxxxxx        quote     <span class="dv">2020-01-09</span> <span class="dv">12</span><span class="sc">:</span><span class="dv">00</span>… xxxxxxxxxxxx…</span>
<span id="cb12-7"><a href="#cb12-7" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxx         xxxxxxxxx       quote     <span class="dv">2020-01-09</span> <span class="dv">09</span><span class="sc">:</span><span class="dv">37</span>… xxxxxxxxxxxx…</span>
<span id="cb12-8"><a href="#cb12-8" tabindex="-1"></a>[snip]</span>
<span id="cb12-9"><a href="#cb12-9" tabindex="-1"></a><span class="co"># … with 1,715 more rows</span></span>
<span id="cb12-10"><a href="#cb12-10" tabindex="-1"></a></span>
<span id="cb12-11"><a href="#cb12-11" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb12-12"><a href="#cb12-12" tabindex="-1"></a><span class="co"># A tibble: 1,158 x 2</span></span>
<span id="cb12-13"><a href="#cb12-13" tabindex="-1"></a>   user_id             screen_name</span>
<span id="cb12-14"><a href="#cb12-14" tabindex="-1"></a>   <span class="sc">&lt;</span>fct<span class="sc">&gt;</span>               <span class="er">&lt;</span>fct<span class="sc">&gt;</span></span>
<span id="cb12-15"><a href="#cb12-15" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxx            xxxx</span>
<span id="cb12-16"><a href="#cb12-16" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxx            xxxxxxxxx</span>
<span id="cb12-17"><a href="#cb12-17" tabindex="-1"></a>[snip]</span>
<span id="cb12-18"><a href="#cb12-18" tabindex="-1"></a><span class="co"># … with 1,148 more rows</span></span>
<span id="cb12-19"><a href="#cb12-19" tabindex="-1"></a></span>
<span id="cb12-20"><a href="#cb12-20" tabindex="-1"></a><span class="fu">attr</span>(,<span class="st">"class"</span>)</span>
<span id="cb12-21"><a href="#cb12-21" tabindex="-1"></a>[<span class="dv">1</span>] <span class="st">"list"</span>    <span class="st">"network"</span> <span class="st">"actor"</span>   <span class="st">"twitter"</span></span></code></pre></div>
<p>This list is then passed to <code><a href="../reference/Graph.html">Graph()</a></code>, which returns an
<code>igraph</code> graph object, and in the above example, the
<code>writeToFile</code> parameter is used to write the graph to file in
<code>GraphML</code> format. The following shows a summary of the
graph:</p>
<div class="sourceCode" id="cb13"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb13-1"><a href="#cb13-1" tabindex="-1"></a><span class="sc">&gt;</span> actorGraph</span>
<span id="cb13-2"><a href="#cb13-2" tabindex="-1"></a>IGRAPH bc177a6 DN<span class="sc">--</span> <span class="dv">1158</span> <span class="dv">1725</span> <span class="sc">--</span></span>
<span id="cb13-3"><a href="#cb13-3" tabindex="-1"></a><span class="sc">+</span> attr<span class="sc">:</span> <span class="fu">type</span> (g<span class="sc">/</span>c), <span class="fu">name</span> (v<span class="sc">/</span>c), <span class="fu">screen_name</span> (v<span class="sc">/</span>c), <span class="fu">label</span> (v<span class="sc">/</span>c),</span>
<span id="cb13-4"><a href="#cb13-4" tabindex="-1"></a><span class="sc">|</span> <span class="fu">edge_type</span> (e<span class="sc">/</span>c), <span class="fu">timestamp</span> (e<span class="sc">/</span>c), <span class="fu">status_id</span> (e<span class="sc">/</span>c)</span>
<span id="cb13-5"><a href="#cb13-5" tabindex="-1"></a><span class="sc">+</span> edges from <span class="fu">bc177a6</span> (vertex names)<span class="sc">:</span></span>
<span id="cb13-6"><a href="#cb13-6" tabindex="-1"></a> [<span class="dv">1</span>] xxxxxxxx           <span class="ot">-&gt;</span>xxxxxxxx</span>
<span id="cb13-7"><a href="#cb13-7" tabindex="-1"></a> [<span class="dv">2</span>] xxxxxxxx           <span class="ot">-&gt;</span>xxxxxxxxx</span>
<span id="cb13-8"><a href="#cb13-8" tabindex="-1"></a>[snip]</span>
<span id="cb13-9"><a href="#cb13-9" tabindex="-1"></a><span class="sc">+</span> ... omitted several edges</span></code></pre></div>
<p>The Twitter actor network contains a graph attribute
<code>type</code> which is set to “twitter” (this attribute is required
for <code>VOSON Dashboard</code>). The following node attributes are
collected from the Twitter profile data: <code>name</code> (Twitter ID),
<code>screen_name</code> (Twitter handle or screen name) and
<code>label</code> (a concatenation of the ID and screen name). The edge
attributes are: <code>edge_type</code> (whether the edge is a mention,
reply, retweet, quoted retweet or self-loop), <code>timestamp</code>
(when the tweet that led to the creation of the edge was authored) and
<code>status_id</code> (the Twitter ID for the tweet).</p>
<p>The example actor network contains 1158 nodes and 1725 edges. The
following code uses <code>igraph</code> functions to: (1) remove all
edges other than reply edges; (2) construct a subnetwork consisting of
the giant component (the largest set of connected nodes); (3) plot this
network.</p>
<div class="sourceCode" id="cb14"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="kw"><a href="https://rdrr.io/r/base/library.html" class="external-link">library</a></span><span class="op">(</span><span class="va"><a href="https://r.igraph.org/" class="external-link">igraph</a></span><span class="op">)</span></span>
<span></span>
<span><span class="co"># remove edges that are not reply edges</span></span>
<span><span class="va">g2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/delete.edges.html" class="external-link">delete.edges</a></span><span class="op">(</span><span class="va">actorGraph</span>, <span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/E.html" class="external-link">E</a></span><span class="op">(</span><span class="va">actorGraph</span><span class="op">)</span><span class="op">$</span><span class="va">edge_type</span> <span class="op">!=</span> <span class="st">"reply"</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># get the giant component</span></span>
<span><span class="va">cc</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/clusters.html" class="external-link">clusters</a></span><span class="op">(</span><span class="va">g2</span><span class="op">)</span></span>
<span><span class="va">g2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/subgraph.html" class="external-link">induced_subgraph</a></span><span class="op">(</span><span class="va">g2</span>, <span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="va">cc</span><span class="op">$</span><span class="va">membership</span> <span class="op">==</span> <span class="fu"><a href="https://rdrr.io/r/base/which.min.html" class="external-link">which.max</a></span><span class="op">(</span><span class="va">cc</span><span class="op">$</span><span class="va">csize</span><span class="op">)</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"twitter_actor_reply_gc.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">g2</span>, vertex.label <span class="op">=</span> <span class="st">""</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>, edge.arrow.size <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/twitter_actor_reply_gc.png" alt="Twitter actor network - replies only - giant component"><div class="figcaption">Twitter actor network - replies only - giant
component</div>
</div>
<p>It is often useful to have the tweet text content in the network.
This can be achieved by using the <code>status_id</code> edge attribute
to pull the tweet text content from the dataframe returned by
<code><a href="../reference/Collect.html">Collect()</a></code>, and store it as an edge attribute.
<code>vosonSML</code> makes this easy with the <code><a href="../reference/AddText.html">AddText()</a></code>
function, with the following example creating a graph with an edge
attribute <code>vosonTxt_tweet</code> which stores the tweet text
content.</p>
<div class="sourceCode" id="cb15"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">actorGraphWithText</span> <span class="op">&lt;-</span> <span class="va">twitterData</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"actor"</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/AddText.html">AddText</a></span><span class="op">(</span><span class="va">twitterData</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p>Now we have tweet text content stored as an edge attribute, we can
use it for text analysis or creating new node attributes. As an example,
the following creates a new node attribute <code>tweetedBushfires</code>
which has the value “yes” if the Twitter user authored at least one
tweet containing the word “bushfire” and “no” otherwise.</p>
<div class="sourceCode" id="cb16"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># get the index of nodes or users who tweeted the word "bushfire"</span></span>
<span><span class="va">ind</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/tail_of.html" class="external-link">tail_of</a></span><span class="op">(</span></span>
<span>  <span class="va">actorGraphWithText</span>,</span>
<span>  <span class="fu"><a href="https://rdrr.io/r/base/grep.html" class="external-link">grep</a></span><span class="op">(</span><span class="st">"bushfire"</span>, <span class="fu"><a href="https://rdrr.io/r/base/chartr.html" class="external-link">tolower</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/E.html" class="external-link">E</a></span><span class="op">(</span><span class="va">actorGraphWithText</span><span class="op">)</span><span class="op">$</span><span class="va">vosonTxt_tweet</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># set node attribute</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">actorGraphWithText</span><span class="op">)</span><span class="op">$</span><span class="va">tweetedBushfires</span> <span class="op">&lt;-</span> <span class="st">"no"</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">actorGraphWithText</span><span class="op">)</span><span class="op">$</span><span class="va">tweetedBushfires</span><span class="op">[</span><span class="va">ind</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"yes"</span></span></code></pre></div>
<p>The following creates and plots the giant component in the reply
network, with red nodes indicating those users who tweeted using the
term “bushfire”.</p>
<div class="sourceCode" id="cb17"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># remove edges that are not reply edges</span></span>
<span><span class="va">g3</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/delete.edges.html" class="external-link">delete.edges</a></span><span class="op">(</span></span>
<span>  <span class="va">actorGraphWithText</span>, <span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/E.html" class="external-link">E</a></span><span class="op">(</span><span class="va">actorGraphWithText</span><span class="op">)</span><span class="op">$</span><span class="va">edge_type</span> <span class="op">!=</span> <span class="st">"reply"</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># get the giant component</span></span>
<span><span class="va">cc</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/clusters.html" class="external-link">clusters</a></span><span class="op">(</span><span class="va">g3</span><span class="op">)</span></span>
<span><span class="va">g3</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/subgraph.html" class="external-link">induced_subgraph</a></span><span class="op">(</span><span class="va">g3</span>, <span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="va">cc</span><span class="op">$</span><span class="va">membership</span> <span class="op">==</span> <span class="fu"><a href="https://rdrr.io/r/base/which.min.html" class="external-link">which.max</a></span><span class="op">(</span><span class="va">cc</span><span class="op">$</span><span class="va">csize</span><span class="op">)</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># set node colour based on tweeted bushfires attribute value</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g3</span><span class="op">)</span><span class="op">$</span><span class="va">color</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html" class="external-link">ifelse</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g3</span><span class="op">)</span><span class="op">$</span><span class="va">tweetedBushfires</span> <span class="op">==</span> <span class="st">"yes"</span>, <span class="st">"red"</span>, <span class="st">"grey"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"twitter_actor_reply_gc_bushfires.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">g3</span>, vertex.label <span class="op">=</span> <span class="st">""</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>, edge.arrow.size <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/twitter_actor_reply_gc_bushfires.png" alt="Twitter actor network - replies only - giant component (red nodes indicate who tweeted at least once about bushfires)"><div class="figcaption">Twitter actor network - replies only - giant
component (red nodes indicate who tweeted at least once about
bushfires)</div>
</div>
<p>The <code>igraph</code> graph object can then be saved to disk as a
<code>GraphML</code> file using the <code>igraph</code> function
<code>write.graph</code>, and later imported into network analysis
software such as <code>igraph</code>, <code>VOSON Dashboard</code> and
<a href="https://gephi.org/" class="external-link">Gephi</a>:</p>
<div class="sourceCode" id="cb18"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># save the graph as a graphml file</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/write.graph.html" class="external-link">write.graph</a></span><span class="op">(</span><span class="va">g3</span>, <span class="st">"twitter_reply_gc_bushfires.graphml"</span>, format <span class="op">=</span> <span class="st">"graphml"</span><span class="op">)</span></span></code></pre></div>
<p>Finally, the <code>AddUserData()</code> function can be used to
create additional node attributes from the Twitter profile, for example,
number of followers and number of tweets authored by the user.</p>
<p>Note that by default, <code>vosonSML</code> will only collect Twitter
profile data for those users who authored tweets that have been
collected. That is, in the above example, profile data will not be
collected (by default) for a user who was mentioned in a tweet that
contained #auspol, but did not author such a tweet. The
<code>lookupUsers</code> argument can be used to make additional Twitter
API calls and collect the profile data for mentioned users whose profile
data is absent, so that their additional profile attributes can also be
added:</p>
<div class="sourceCode" id="cb19"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># create an actor network with user metadata</span></span>
<span><span class="va">actorGraphWithUserAttr</span> <span class="op">&lt;-</span> <span class="va">actorNetwork</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu">AddUserData</span><span class="op">(</span><span class="va">twitterData</span>, lookupUsers <span class="op">=</span> <span class="cn">TRUE</span>, twitterAuth <span class="op">=</span> <span class="va">twitterAuth</span><span class="op">)</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span>writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level4">
<h4 id="activity-network">Activity Network<a class="anchor" aria-label="anchor" href="#activity-network"></a>
</h4>
<p>In the Twitter <em>activity network</em>, nodes represent tweets and
edge types are: replies, retweets and quoted retweets.</p>
<div class="sourceCode" id="cb20"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># create an activity network with tweet text</span></span>
<span><span class="va">activityNetwork</span> <span class="op">&lt;-</span> <span class="va">twitterData</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"activity"</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/AddText.html">AddText</a></span><span class="op">(</span><span class="va">twitterData</span><span class="op">)</span></span>
<span><span class="va">activityGraph</span> <span class="op">&lt;-</span> <span class="va">activityNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span>writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p><code>Create("activity")</code> returns a named list containing two
dataframes named “nodes” and “edges” (the following has been modified to
preserve anonymity):</p>
<div class="sourceCode" id="cb21"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb21-1"><a href="#cb21-1" tabindex="-1"></a><span class="sc">&gt;</span> activityNetwork</span>
<span id="cb21-2"><a href="#cb21-2" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb21-3"><a href="#cb21-3" tabindex="-1"></a><span class="co"># A tibble: 1,408 x 5</span></span>
<span id="cb21-4"><a href="#cb21-4" tabindex="-1"></a>   status_id    user_id    screen_name created_at   vosonTxt_tweet</span>
<span id="cb21-5"><a href="#cb21-5" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>        <span class="er">&lt;</span>chr<span class="sc">&gt;</span>      <span class="er">&lt;</span>chr<span class="sc">&gt;</span>       <span class="er">&lt;</span>chr<span class="sc">&gt;</span>        <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb21-6"><a href="#cb21-6" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxxxxx… xxxxxxxx   xxxx        <span class="dv">2020-01-09</span> … <span class="st">"xxxxxxxxxxxxxxxxxxxxx…</span></span>
<span id="cb21-7"><a href="#cb21-7" tabindex="-1"></a><span class="st"> 2 xxxxxxxxxxx… xxxxxxxx   xxxxxxxxx   2020-01-09 … "</span>xxxxxxxxxxxxxxxxxxxxx…</span>
<span id="cb21-8"><a href="#cb21-8" tabindex="-1"></a> [snip]</span>
<span id="cb21-9"><a href="#cb21-9" tabindex="-1"></a> <span class="co"># … with 1,398 more rows</span></span>
<span id="cb21-10"><a href="#cb21-10" tabindex="-1"></a></span>
<span id="cb21-11"><a href="#cb21-11" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb21-12"><a href="#cb21-12" tabindex="-1"></a><span class="co"># A tibble: 662 x 3</span></span>
<span id="cb21-13"><a href="#cb21-13" tabindex="-1"></a>   from                to                  edge_type</span>
<span id="cb21-14"><a href="#cb21-14" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>               <span class="er">&lt;</span>chr<span class="sc">&gt;</span>               <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb21-15"><a href="#cb21-15" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx quote</span>
<span id="cb21-16"><a href="#cb21-16" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxxxxxxx quote</span>
<span id="cb21-17"><a href="#cb21-17" tabindex="-1"></a>[snip]</span>
<span id="cb21-18"><a href="#cb21-18" tabindex="-1"></a><span class="co"># … with 652 more rows</span></span>
<span id="cb21-19"><a href="#cb21-19" tabindex="-1"></a></span>
<span id="cb21-20"><a href="#cb21-20" tabindex="-1"></a><span class="fu">attr</span>(,<span class="st">"class"</span>)</span>
<span id="cb21-21"><a href="#cb21-21" tabindex="-1"></a>[<span class="dv">1</span>] <span class="st">"list"</span>       <span class="st">"network"</span>    <span class="st">"activity"</span>   <span class="st">"twitter"</span>    <span class="st">"voson_text"</span></span></code></pre></div>
<p>Note that in the above, <code><a href="../reference/AddText.html">AddText()</a></code> was used to add the
comment text data to the network dataframe, stored as a node attribute.
This list is then passed to <code><a href="../reference/Graph.html">Graph()</a></code>, which returns an
<code>igraph</code> graph object (the following has been
anonymised):</p>
<div class="sourceCode" id="cb22"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb22-1"><a href="#cb22-1" tabindex="-1"></a><span class="sc">&gt;</span> activityGraph</span>
<span id="cb22-2"><a href="#cb22-2" tabindex="-1"></a>IGRAPH e60c486 DN<span class="sc">--</span> <span class="dv">1408</span> <span class="dv">662</span> <span class="sc">--</span></span>
<span id="cb22-3"><a href="#cb22-3" tabindex="-1"></a><span class="sc">+</span> attr<span class="sc">:</span> <span class="fu">type</span> (g<span class="sc">/</span>c), <span class="fu">name</span> (v<span class="sc">/</span>c), <span class="fu">user_id</span> (v<span class="sc">/</span>c), <span class="fu">screen_name</span> (v<span class="sc">/</span>c),</span>
<span id="cb22-4"><a href="#cb22-4" tabindex="-1"></a><span class="sc">|</span> <span class="fu">created_at</span> (v<span class="sc">/</span>c), <span class="fu">vosonTxt_tweet</span> (v<span class="sc">/</span>c), <span class="fu">label</span> (v<span class="sc">/</span>c), <span class="fu">edge_type</span> (e<span class="sc">/</span>c)</span>
<span id="cb22-5"><a href="#cb22-5" tabindex="-1"></a><span class="sc">+</span> edges from <span class="fu">e60c486</span> (vertex names)<span class="sc">:</span></span>
<span id="cb22-6"><a href="#cb22-6" tabindex="-1"></a> [<span class="dv">1</span>] xxxx<span class="ot">-&gt;</span>xxxx</span>
<span id="cb22-7"><a href="#cb22-7" tabindex="-1"></a> [<span class="dv">2</span>] xxxx<span class="ot">-&gt;</span>xxxx</span>
<span id="cb22-8"><a href="#cb22-8" tabindex="-1"></a>[snip]</span>
<span id="cb22-9"><a href="#cb22-9" tabindex="-1"></a><span class="sc">+</span> ... omitted several edges</span></code></pre></div>
<p>The Twitter activity network contains a graph attribute
<code>type</code> (set to “twitter”). The node attributes are:
<code>name</code> (Twitter ID for the tweet), <code>user_id</code>
(Twitter ID for the user who authored the tweet),
<code>screen_name</code> (Twitter handle or screen name of the user who
authored the tweet), <code>created_at</code> (timestamp when the tweet
was authored), <code>vosonTxt_tweet</code> (text content of the tweet)
and <code>label</code> (a concatenation of <code>name</code> and
<code>user_id</code>). The edge attribute is <code>edge_type</code>
which can have the value ‘reply’, ‘retweet’ or ‘quote’.</p>
<p>The example Twitter activity network contains 1408 nodes and 662
edges. The following is a visualization of the network, where nodes are
tweets and tweets mentioning bushfires are indicated in red.</p>
<div class="sourceCode" id="cb23"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># create a subgraph containing nodes of components that have more than 5 nodes</span></span>
<span><span class="va">cc</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/clusters.html" class="external-link">clusters</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span></span>
<span><span class="va">g4</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/subgraph.html" class="external-link">induced_subgraph</a></span><span class="op">(</span></span>
<span>  <span class="va">activityGraph</span>,</span>
<span>  <span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="va">cc</span><span class="op">$</span><span class="va">membership</span> <span class="op"><a href="https://rdrr.io/r/base/match.html" class="external-link">%in%</a></span> <span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="va">cc</span><span class="op">$</span><span class="va">csize</span> <span class="op">&gt;</span> <span class="fl">5</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># set node colour based on if tweet contains the word "bushfire"</span></span>
<span><span class="va">ind</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/grep.html" class="external-link">grep</a></span><span class="op">(</span><span class="st">"bushfire"</span>, <span class="fu"><a href="https://rdrr.io/r/base/chartr.html" class="external-link">tolower</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g4</span><span class="op">)</span><span class="op">$</span><span class="va">vosonTxt_tweet</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g4</span><span class="op">)</span><span class="op">$</span><span class="va">color</span> <span class="op">&lt;-</span> <span class="st">"grey"</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g4</span><span class="op">)</span><span class="op">$</span><span class="va">color</span><span class="op">[</span><span class="va">ind</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"red"</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"twitter_activity.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">g4</span>, vertex.label <span class="op">=</span> <span class="st">""</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>, edge.arrow.size <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/twitter_activity.png" alt="Twitter activity network (red indicates tweets mentioning bushfires)"><div class="figcaption">Twitter activity network (red indicates tweets
mentioning bushfires)</div>
</div>
<p>It should be noted that a limitation of the Twitter API is that
retweet chains are not provided. This means that if user <em>i</em>
tweeted an original tweet, and then user <em>j</em> retweeted this
tweet, and user <em>k</em> retweeted <em>j</em>’s retweet, the activity
network will show edges connecting the two retweets to the original
tweet.</p>
</div>
<div class="section level4">
<h4 id="mode-network">2-mode Network<a class="anchor" aria-label="anchor" href="#mode-network"></a>
</h4>
<p>In the Twitter <em>2-mode network</em>, the two types of nodes are
actors (Twitter users) and hashtags. There is an edge from user
<em>i</em> to hashtag <em>j</em> if user <em>i</em> authored a tweet
containing hashtag <em>j</em>.</p>
<div class="sourceCode" id="cb24"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># create a 2-mode network with the hashtag "#auspol" removed</span></span>
<span><span class="va">twomodeNetwork</span> <span class="op">&lt;-</span> <span class="va">twitterData</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"twomode"</span>, removeTermsOrHashtags <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"#auspol"</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="va">twomodeGraph</span> <span class="op">&lt;-</span> <span class="va">twomodeNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p><code>Create("twomode")</code> returns a named list containing two
dataframes named “nodes” and “edges” (the following has been modified to
preserve anonymity). Note that in this example, the
<code>removeTermsOrHashtags</code> argument was used to exclude
‘#auspol’, since by construction all tweets contained this hashtag.</p>
<div class="sourceCode" id="cb25"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb25-1"><a href="#cb25-1" tabindex="-1"></a><span class="sc">&gt;</span> twomodeNetwork</span>
<span id="cb25-2"><a href="#cb25-2" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb25-3"><a href="#cb25-3" tabindex="-1"></a><span class="co"># A tibble: 1,146 x 2</span></span>
<span id="cb25-4"><a href="#cb25-4" tabindex="-1"></a>   entity_id                    display_name</span>
<span id="cb25-5"><a href="#cb25-5" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>                        <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb25-6"><a href="#cb25-6" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxx                     xxxx</span>
<span id="cb25-7"><a href="#cb25-7" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxx                     xxxxxxxxx</span>
<span id="cb25-8"><a href="#cb25-8" tabindex="-1"></a> <span class="dv">3</span> <span class="co">#auspol2020                  #auspol2020</span></span>
<span id="cb25-9"><a href="#cb25-9" tabindex="-1"></a> <span class="dv">4</span> <span class="co">#australianbushfiredisaster  #australianbushfiredisaster</span></span>
<span id="cb25-10"><a href="#cb25-10" tabindex="-1"></a>[snip]</span>
<span id="cb25-11"><a href="#cb25-11" tabindex="-1"></a><span class="co"># … with 1,136 more rows</span></span>
<span id="cb25-12"><a href="#cb25-12" tabindex="-1"></a></span>
<span id="cb25-13"><a href="#cb25-13" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb25-14"><a href="#cb25-14" tabindex="-1"></a><span class="co"># A tibble: 1,675 x 5</span></span>
<span id="cb25-15"><a href="#cb25-15" tabindex="-1"></a>   from      to                      edge_type timestamp        status_id</span>
<span id="cb25-16"><a href="#cb25-16" tabindex="-1"></a>   <span class="sc">&lt;</span>fct<span class="sc">&gt;</span>     <span class="er">&lt;</span>fct<span class="sc">&gt;</span>                   <span class="er">&lt;</span>fct<span class="sc">&gt;</span>     <span class="er">&lt;</span>fct<span class="sc">&gt;</span>            <span class="er">&lt;</span>fct<span class="sc">&gt;</span></span>
<span id="cb25-17"><a href="#cb25-17" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxx  <span class="co">#auspol2020             hashtag   2020-01-09 12:0… xxxxxxxxxxxx…</span></span>
<span id="cb25-18"><a href="#cb25-18" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxx  <span class="co">#australianbushfiredis… hashtag   2020-01-09 12:0… xxxxxxxxxxxx…</span></span>
<span id="cb25-19"><a href="#cb25-19" tabindex="-1"></a>[snip]</span>
<span id="cb25-20"><a href="#cb25-20" tabindex="-1"></a><span class="co"># … with 1,665 more rows</span></span>
<span id="cb25-21"><a href="#cb25-21" tabindex="-1"></a></span>
<span id="cb25-22"><a href="#cb25-22" tabindex="-1"></a><span class="fu">attr</span>(,<span class="st">"class"</span>)</span>
<span id="cb25-23"><a href="#cb25-23" tabindex="-1"></a>[<span class="dv">1</span>] <span class="st">"list"</span>    <span class="st">"network"</span> <span class="st">"twomode"</span> <span class="st">"twitter"</span></span></code></pre></div>
<p>This list is then passed to <code><a href="../reference/Graph.html">Graph()</a></code>, which returns an
<code>igraph</code> graph object (this has been anonymised):</p>
<div class="sourceCode" id="cb26"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb26-1"><a href="#cb26-1" tabindex="-1"></a><span class="sc">&gt;</span> twomodeGraph</span>
<span id="cb26-2"><a href="#cb26-2" tabindex="-1"></a>IGRAPH <span class="dv">68</span>bd240 DN<span class="sc">--</span> <span class="dv">1146</span> <span class="dv">1675</span> <span class="sc">--</span></span>
<span id="cb26-3"><a href="#cb26-3" tabindex="-1"></a><span class="sc">+</span> attr<span class="sc">:</span> <span class="fu">type</span> (g<span class="sc">/</span>c), <span class="fu">name</span> (v<span class="sc">/</span>c), <span class="fu">display_name</span> (v<span class="sc">/</span>c), <span class="fu">label</span> (v<span class="sc">/</span>c),</span>
<span id="cb26-4"><a href="#cb26-4" tabindex="-1"></a><span class="sc">|</span> <span class="fu">edge_type</span> (e<span class="sc">/</span>c), <span class="fu">timestamp</span> (e<span class="sc">/</span>c), <span class="fu">status_id</span> (e<span class="sc">/</span>c)</span>
<span id="cb26-5"><a href="#cb26-5" tabindex="-1"></a><span class="sc">+</span> edges from <span class="dv">68</span><span class="fu">bd240</span> (vertex names)<span class="sc">:</span></span>
<span id="cb26-6"><a href="#cb26-6" tabindex="-1"></a> [<span class="dv">1</span>] xxxx <span class="ot">-&gt;</span> <span class="co">#auspol2020</span></span>
<span id="cb26-7"><a href="#cb26-7" tabindex="-1"></a> [<span class="dv">2</span>] xxxx <span class="ot">-&gt;</span> <span class="co">#australianbushfiredisaster</span></span>
<span id="cb26-8"><a href="#cb26-8" tabindex="-1"></a>[snip]</span>
<span id="cb26-9"><a href="#cb26-9" tabindex="-1"></a><span class="sc">+</span> ... omitted several edges</span></code></pre></div>
<p>The Twitter 2-model network has a graph attribute <code>type</code>
(set to “twitter”). The node attributes are: <code>name</code> (hashtag
or Twitter user ID), <code>display_name</code> (hashtag or Twitter
handle or screen name), <code>label</code> (for users, a concatenation
of <code>name</code> and <code>display_name</code>, while for hashtags
it is <code>name</code>). The edge attributes are:
<code>edge_type</code> (‘hashtag’), <code>timestamp</code> (timestamp of
the tweet that led to the edge), <code>status_id</code> (Twitter ID of
the tweet that led to the edge).</p>
<div class="sourceCode" id="cb27"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># get index of nodes that are in the top 5 by highest in-degree</span></span>
<span><span class="co"># this is the top 5 used hashtags, as all users have 0 in-degree</span></span>
<span><span class="co"># in this network</span></span>
<span><span class="va">ind</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/order.html" class="external-link">order</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/degree.html" class="external-link">degree</a></span><span class="op">(</span><span class="va">twomodeGraph</span>, mode <span class="op">=</span> <span class="st">"in"</span><span class="op">)</span>, decreasing <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span><span class="op">[</span><span class="fl">1</span><span class="op">:</span><span class="fl">5</span><span class="op">]</span></span>
<span></span>
<span><span class="co"># get index of nodes with an edge directed to the top 5 hashtags</span></span>
<span><span class="co"># this is users who have tweeted with these hashtags</span></span>
<span><span class="va">ind2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/unlist.html" class="external-link">unlist</a></span><span class="op">(</span></span>
<span>  <span class="fu"><a href="https://rdrr.io/r/base/lapply.html" class="external-link">lapply</a></span><span class="op">(</span><span class="va">ind</span>, <span class="kw">function</span><span class="op">(</span><span class="va">x</span><span class="op">)</span> <span class="fu"><a href="https://r.igraph.org/reference/neighbors.html" class="external-link">neighbors</a></span><span class="op">(</span><span class="va">twomodeGraph</span>, <span class="va">x</span>, mode <span class="op">=</span> <span class="st">"in"</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># create a subgraph containing only the top 5 used hashtags and related users</span></span>
<span><span class="va">g5</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/subgraph.html" class="external-link">induced_subgraph</a></span><span class="op">(</span><span class="va">twomodeGraph</span>, <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="va">ind</span>, <span class="fu"><a href="https://rdrr.io/r/base/numeric.html" class="external-link">as.numeric</a></span><span class="op">(</span><span class="va">ind2</span><span class="op">)</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># set node colour and label based on in-degree</span></span>
<span><span class="co"># only hashtag nodes are set to blue and with label attribute set</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g5</span><span class="op">)</span><span class="op">$</span><span class="va">color</span> <span class="op">&lt;-</span> <span class="st">"grey"</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g5</span><span class="op">)</span><span class="op">$</span><span class="va">color</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/degree.html" class="external-link">degree</a></span><span class="op">(</span><span class="va">g5</span>, mode <span class="op">=</span> <span class="st">"in"</span><span class="op">)</span> <span class="op">&gt;</span> <span class="fl">0</span><span class="op">)</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"blue"</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g5</span><span class="op">)</span><span class="op">$</span><span class="va">label2</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html" class="external-link">ifelse</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/degree.html" class="external-link">degree</a></span><span class="op">(</span><span class="va">g5</span>, mode <span class="op">=</span> <span class="st">"in"</span><span class="op">)</span> <span class="op">&gt;</span> <span class="fl">0</span>, <span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g5</span><span class="op">)</span><span class="op">$</span><span class="va">label</span>, <span class="st">""</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"twitter_twomode.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">g5</span>, vertex.label <span class="op">=</span> <span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g5</span><span class="op">)</span><span class="op">$</span><span class="va">label2</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>, edge.arrow.size <span class="op">=</span> <span class="fl">0.5</span>,</span>
<span>     vertex.label.cex <span class="op">=</span> <span class="fl">1.8</span>, vertex.label.color <span class="op">=</span> <span class="st">"red"</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/twitter_twomode.png" alt="Twitter 2-mode network - top-5 hashtags, and the users who tweeted them"><div class="figcaption">Twitter 2-mode network - top-5 hashtags, and the
users who tweeted them</div>
</div>
</div>
<div class="section level4">
<h4 id="semantic-network">Semantic Network<a class="anchor" aria-label="anchor" href="#semantic-network"></a>
</h4>
<p>In the Twitter <em>semantic network</em>, nodes represent entities
extracted from the tweet text: common words, hashtags and usernames.
Edges reflect co-occurrence i.e. there is an edge between entities
<em>i</em> and <em>j</em> if they both occurred in the same tweet.</p>
<div class="sourceCode" id="cb28"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># additional required packages for tokenization</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/utils/install.packages.html" class="external-link">install.packages</a></span><span class="op">(</span><span class="st">"stopwords"</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># create a semantic network with some common terms removed</span></span>
<span><span class="co"># include only the top 5% occurring terms in the network</span></span>
<span><span class="va">semanticNetwork</span> <span class="op">&lt;-</span> <span class="va">twitterData</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span></span>
<span>   <span class="st">"semantic"</span>,</span>
<span>   removeTermsOrHashtags <span class="op">=</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span><span class="st">"#auspol"</span>, <span class="st">"auspol"</span>, <span class="st">"australia"</span><span class="op">)</span>,</span>
<span>   termFreq <span class="op">=</span> <span class="fl">5</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># create an undirected graph</span></span>
<span><span class="va">semanticGraph</span> <span class="op">&lt;-</span> <span class="va">semanticNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span>directed <span class="op">=</span> <span class="cn">FALSE</span><span class="op">)</span></span></code></pre></div>
<p><code>Create("semantic")</code> returns a named list containing two
dataframes named “nodes” and “edges”:</p>
<div class="sourceCode" id="cb29"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb29-1"><a href="#cb29-1" tabindex="-1"></a><span class="sc">&gt;</span> semanticNetwork</span>
<span id="cb29-2"><a href="#cb29-2" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb29-3"><a href="#cb29-3" tabindex="-1"></a><span class="co"># A tibble: 799 x 1</span></span>
<span id="cb29-4"><a href="#cb29-4" tabindex="-1"></a>   value</span>
<span id="cb29-5"><a href="#cb29-5" tabindex="-1"></a>   <span class="sc">&lt;</span>fct<span class="sc">&gt;</span></span>
<span id="cb29-6"><a href="#cb29-6" tabindex="-1"></a> <span class="dv">1</span> just</span>
<span id="cb29-7"><a href="#cb29-7" tabindex="-1"></a> <span class="dv">2</span> one</span>
<span id="cb29-8"><a href="#cb29-8" tabindex="-1"></a> <span class="dv">3</span> fire</span>
<span id="cb29-9"><a href="#cb29-9" tabindex="-1"></a> <span class="dv">4</span> going</span>
<span id="cb29-10"><a href="#cb29-10" tabindex="-1"></a> <span class="dv">5</span> still</span>
<span id="cb29-11"><a href="#cb29-11" tabindex="-1"></a> <span class="dv">6</span> hard</span>
<span id="cb29-12"><a href="#cb29-12" tabindex="-1"></a> <span class="dv">7</span> trying</span>
<span id="cb29-13"><a href="#cb29-13" tabindex="-1"></a> <span class="dv">8</span> since</span>
<span id="cb29-14"><a href="#cb29-14" tabindex="-1"></a> <span class="dv">9</span> try</span>
<span id="cb29-15"><a href="#cb29-15" tabindex="-1"></a><span class="dv">10</span> sick</span>
<span id="cb29-16"><a href="#cb29-16" tabindex="-1"></a><span class="co"># … with 789 more rows</span></span>
<span id="cb29-17"><a href="#cb29-17" tabindex="-1"></a></span>
<span id="cb29-18"><a href="#cb29-18" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb29-19"><a href="#cb29-19" tabindex="-1"></a><span class="co"># A tibble: 10,990 x 3</span></span>
<span id="cb29-20"><a href="#cb29-20" tabindex="-1"></a>   from        to                           weight</span>
<span id="cb29-21"><a href="#cb29-21" tabindex="-1"></a>   <span class="sc">&lt;</span>fct<span class="sc">&gt;</span>       <span class="er">&lt;</span>fct<span class="sc">&gt;</span>                         <span class="er">&lt;</span>int<span class="sc">&gt;</span></span>
<span id="cb29-22"><a href="#cb29-22" tabindex="-1"></a> <span class="dv">1</span> <span class="co">#auspol2020 #australianbushfiredisaster       2</span></span>
<span id="cb29-23"><a href="#cb29-23" tabindex="-1"></a> <span class="dv">2</span> <span class="co">#auspol2020 government                        2</span></span>
<span id="cb29-24"><a href="#cb29-24" tabindex="-1"></a> <span class="dv">3</span> <span class="co">#auspol2020 fire                              4</span></span>
<span id="cb29-25"><a href="#cb29-25" tabindex="-1"></a> <span class="dv">4</span> <span class="co">#auspol2020 australian                        2</span></span>
<span id="cb29-26"><a href="#cb29-26" tabindex="-1"></a> <span class="dv">5</span> <span class="co">#auspol2020 bushfire                          2</span></span>
<span id="cb29-27"><a href="#cb29-27" tabindex="-1"></a> <span class="dv">6</span> <span class="co">#auspol2020 fires                             4</span></span>
<span id="cb29-28"><a href="#cb29-28" tabindex="-1"></a> <span class="dv">7</span> <span class="co">#auspol2020 #australiafires                   1</span></span>
<span id="cb29-29"><a href="#cb29-29" tabindex="-1"></a> <span class="dv">8</span> <span class="co">#auspol2020 #australianbushfiresdisaster      1</span></span>
<span id="cb29-30"><a href="#cb29-30" tabindex="-1"></a> <span class="dv">9</span> <span class="co">#auspol2020 #australia                        4</span></span>
<span id="cb29-31"><a href="#cb29-31" tabindex="-1"></a><span class="dv">10</span> <span class="co">#auspol2020 bushfires                         2</span></span>
<span id="cb29-32"><a href="#cb29-32" tabindex="-1"></a><span class="co"># … with 10,980 more rows</span></span>
<span id="cb29-33"><a href="#cb29-33" tabindex="-1"></a></span>
<span id="cb29-34"><a href="#cb29-34" tabindex="-1"></a><span class="fu">attr</span>(,<span class="st">"class"</span>)</span>
<span id="cb29-35"><a href="#cb29-35" tabindex="-1"></a>[<span class="dv">1</span>] <span class="st">"list"</span>     <span class="st">"network"</span>  <span class="st">"semantic"</span> <span class="st">"twitter"</span></span></code></pre></div>
<p>The <code>removeTermsOrHashtags</code> argument is used to exclude
terms that we can expect to occur frequently (e.g. because of the
parameters used for the data collection). The <code>termFreq</code>
parameter is used to limit the network to the top 5 percent most
frequently occurring entities.</p>
<p>This list is then passed to <code><a href="../reference/Graph.html">Graph()</a></code>, which returns an
<code>igraph</code> graph object:</p>
<div class="sourceCode" id="cb30"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb30-1"><a href="#cb30-1" tabindex="-1"></a><span class="sc">&gt;</span> semanticGraph</span>
<span id="cb30-2"><a href="#cb30-2" tabindex="-1"></a>IGRAPH cb8c381 UNW<span class="sc">-</span> <span class="dv">799</span> <span class="dv">10990</span> <span class="sc">--</span></span>
<span id="cb30-3"><a href="#cb30-3" tabindex="-1"></a><span class="sc">+</span> attr<span class="sc">:</span> <span class="fu">type</span> (g<span class="sc">/</span>c), <span class="fu">name</span> (v<span class="sc">/</span>c), <span class="fu">label</span> (v<span class="sc">/</span>c), <span class="fu">weight</span> (e<span class="sc">/</span>n)</span>
<span id="cb30-4"><a href="#cb30-4" tabindex="-1"></a><span class="sc">+</span> edges from <span class="fu">cb8c381</span> (vertex names)<span class="sc">:</span></span>
<span id="cb30-5"><a href="#cb30-5" tabindex="-1"></a> [<span class="dv">1</span>] <span class="co">#australianbushfiredisaster --#auspol2020</span></span>
<span id="cb30-6"><a href="#cb30-6" tabindex="-1"></a> [<span class="dv">2</span>] government                  <span class="sc">--</span><span class="co">#auspol2020</span></span>
<span id="cb30-7"><a href="#cb30-7" tabindex="-1"></a> [<span class="dv">3</span>] fire                        <span class="sc">--</span><span class="co">#auspol2020</span></span>
<span id="cb30-8"><a href="#cb30-8" tabindex="-1"></a> [<span class="dv">4</span>] australian                  <span class="sc">--</span><span class="co">#auspol2020</span></span>
<span id="cb30-9"><a href="#cb30-9" tabindex="-1"></a> [<span class="dv">5</span>] bushfire                    <span class="sc">--</span><span class="co">#auspol2020</span></span>
<span id="cb30-10"><a href="#cb30-10" tabindex="-1"></a> [<span class="dv">6</span>] fires                       <span class="sc">--</span><span class="co">#auspol2020</span></span>
<span id="cb30-11"><a href="#cb30-11" tabindex="-1"></a> [<span class="dv">7</span>] <span class="co">#australiafires             --#auspol2020</span></span>
<span id="cb30-12"><a href="#cb30-12" tabindex="-1"></a> [<span class="dv">8</span>] <span class="co">#australianbushfiresdisaster--#auspol2020</span></span>
<span id="cb30-13"><a href="#cb30-13" tabindex="-1"></a><span class="sc">+</span> ... omitted several edges</span></code></pre></div>
<p>The Twitter semantic network node contains a graph attribute
<code>type</code> (set to “twitter”). The node attributes are:
<code>name</code> (the entity i.e. hashtag or word), <code>label</code>
(same as <code>name</code>). The edge attribute is <code>weight</code>
(how many tweets the two entities co-occurred in).</p>
<p>The example Twitter semantic network has 799 nodes and 10990 edges.
The following produces a visualisation of subnetwork of terms that
contain the string “bushfire”:</p>
<div class="sourceCode" id="cb31"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># get index of the nodes whose term contains "bushfire"</span></span>
<span><span class="va">ind</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/grep.html" class="external-link">grep</a></span><span class="op">(</span><span class="st">"bushfire"</span>, <span class="fu"><a href="https://rdrr.io/r/base/chartr.html" class="external-link">tolower</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">semanticGraph</span><span class="op">)</span><span class="op">$</span><span class="va">name</span><span class="op">)</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># create a subgraph containing only bushfire terms</span></span>
<span><span class="va">g6</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/subgraph.html" class="external-link">induced_subgraph</a></span><span class="op">(</span><span class="va">semanticGraph</span>, <span class="va">ind</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="co"># plotted with large-graph-layout algorithm and edge weights</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"twitter_semantic.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">g6</span>, layout <span class="op">=</span> <span class="fu"><a href="https://r.igraph.org/reference/layout_with_lgl.html" class="external-link">layout_with_lgl</a></span><span class="op">(</span><span class="va">g6</span><span class="op">)</span>, vertex.shape <span class="op">=</span> <span class="st">"none"</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>,</span>
<span>     edge.width <span class="op">=</span> <span class="fl">1</span> <span class="op">+</span> <span class="fu"><a href="https://rdrr.io/r/base/Log.html" class="external-link">log</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/E.html" class="external-link">E</a></span><span class="op">(</span><span class="va">g2</span><span class="op">)</span><span class="op">$</span><span class="va">weight</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/twitter_semantic.png" alt="Twitter semantic network - entities containing the word “bushfire” (edge thickness proportional to edge weight)"><div class="figcaption">Twitter semantic network - entities containing
the word “bushfire” (edge thickness proportional to edge weight)</div>
</div>
</div>
</div>
</div>
<div class="section level2">
<h2 id="youtube">YouTube<a class="anchor" aria-label="anchor" href="#youtube"></a>
</h2>
<div class="section level3">
<h3 id="authenticating-with-the-youtube-api">Authenticating with the YouTube API<a class="anchor" aria-label="anchor" href="#authenticating-with-the-youtube-api"></a>
</h3>
<p>To collect YouTube data, it is necessary to first create a Google app
with access to the YouTube Data API via the <a href="https://console.developers.google.com/apis" class="external-link">Google APIs
console</a> and generate an associated API key. The following shows the
creation of a YouTube access token by passing a Google developer API key
to the <code>Autnenticate()</code> function:</p>
<div class="sourceCode" id="cb32"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># create auth object with api key</span></span>
<span><span class="va">youtubeAuth</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Authenticate.html">Authenticate</a></span><span class="op">(</span><span class="st">"youtube"</span>, apiKey <span class="op">=</span> <span class="st">"xxxxxxxx"</span><span class="op">)</span></span></code></pre></div>
<p>As with the Twitter example above, the YouTube access token can
optionally be saved to disk for use in a later session.</p>
</div>
<div class="section level3">
<h3 id="collecting-data-from-youtube">Collecting Data from YouTube<a class="anchor" aria-label="anchor" href="#collecting-data-from-youtube"></a>
</h3>
<p>The YouTube video IDs (the part after “=” in the YouTube URL) are
required in order to collect YouTube comment data. These IDs can either
be manually provided or automatically extracted from the URLs:</p>
<div class="sourceCode" id="cb33"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb33-1"><a href="#cb33-1" tabindex="-1"></a>videoIDs <span class="ot">&lt;-</span> <span class="fu">c</span>(</span>
<span id="cb33-2"><a href="#cb33-2" tabindex="-1"></a>  <span class="st">"xxxxxx"</span>,</span>
<span id="cb33-3"><a href="#cb33-3" tabindex="-1"></a>  <span class="st">"https://www.youtube.com/watch?v=xxxxxxxx"</span>,</span>
<span id="cb33-4"><a href="#cb33-4" tabindex="-1"></a>  <span class="st">"https://youtu.be/xxxxxxxx"</span>)</span>
<span id="cb33-5"><a href="#cb33-5" tabindex="-1"></a><span class="er">)</span></span></code></pre></div>
<p>The character vector containing the YouTube video IDs or URLs is
passed as a parameter to the <code><a href="../reference/Collect.html">Collect()</a></code> function (the
following code also shows the YouTube access token being piped to
<code><a href="../reference/Collect.html">Collect()</a></code>). In the following example, we are collecting
comments from a YouTube video titled “Australia bushfires - a national
catastrophe | DW News”, which was uploaded by the German Deutsche Welle
news service on 5th January 2020. The comment data were collected on
10th January 2020: the total number of comments at that time was over
1100, but we are using the <code>maxComments</code> parameter to collect
a maximum of 500 top-level comments (and all the reply comments to these
top-level comments).</p>
<div class="sourceCode" id="cb34"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">videoID</span> <span class="op">&lt;-</span> <span class="st">"https://www.youtube.com/watch?v=pJ_NyEYRkLQ"</span></span>
<span><span class="va">youtubeData</span> <span class="op">&lt;-</span> <span class="va">youtubeAuth</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu"><a href="../reference/Collect.html">Collect</a></span><span class="op">(</span><span class="va">videoID</span>, maxComments <span class="op">=</span> <span class="fl">500</span>, writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p>The <code><a href="../reference/Collect.html">Collect()</a></code> function takes the following arguments
(when used for collecting YouTube data): <code>credential</code> (object
generated from <code><a href="../reference/Authenticate.html">Authenticate()</a></code> with class name “youtube”
(above we pass this via the pipe), <code>videoIDs</code> (character
vector specifying one or more youtube video IDs),
<code>maxComments</code> (numeric integer specifying how many top-level
comments to collect from each video), <code>writeToFile</code> (whether
to write the returned dataframe to disk as an <code>.rds</code> file;
default is FALSE), and <code>verbose</code> (whether to output
information about the data collection; default is FALSE).</p>
<p><code><a href="../reference/Collect.html">Collect()</a></code> returns an R dataframe with the following
structure (data have been modified to preserve anonymity):</p>
<div class="sourceCode" id="cb35"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb35-1"><a href="#cb35-1" tabindex="-1"></a><span class="sc">&gt;</span> <span class="fu">str</span>(youtubeData)</span>
<span id="cb35-2"><a href="#cb35-2" tabindex="-1"></a>Classes ‘dataource’, ‘youtube’ and <span class="st">'data.frame'</span><span class="sc">:</span>    <span class="dv">603</span> obs. of  <span class="dv">12</span> variables<span class="sc">:</span></span>
<span id="cb35-3"><a href="#cb35-3" tabindex="-1"></a> <span class="er">$</span> Comment              <span class="sc">:</span> chr  <span class="st">"xxxxx"</span></span>
<span id="cb35-4"><a href="#cb35-4" tabindex="-1"></a> <span class="sc">$</span> AuthorDisplayName    <span class="sc">:</span> chr  <span class="st">"xx"</span> <span class="st">"xx"</span> <span class="st">"xx"</span> <span class="st">"xx"</span></span>
<span id="cb35-5"><a href="#cb35-5" tabindex="-1"></a> <span class="sc">$</span> AuthorProfileImageUrl<span class="sc">:</span> chr  <span class="st">"https://xx"</span> <span class="st">"https://xx"</span> <span class="st">"https://xx"</span></span>
<span id="cb35-6"><a href="#cb35-6" tabindex="-1"></a> <span class="sc">$</span> AuthorChannelUrl     <span class="sc">:</span> chr  <span class="st">"http://xx"</span> <span class="st">"http://xx"</span> <span class="st">"http://xx"</span> <span class="st">"http://xx"</span></span>
<span id="cb35-7"><a href="#cb35-7" tabindex="-1"></a> <span class="sc">$</span> AuthorChannelID      <span class="sc">:</span> chr  <span class="st">"xx"</span> <span class="st">"xx"</span> <span class="st">"xx"</span> <span class="st">"xx"</span></span>
<span id="cb35-8"><a href="#cb35-8" tabindex="-1"></a> <span class="sc">$</span> ReplyCount           <span class="sc">:</span> chr  <span class="st">"0"</span> <span class="st">"0"</span> <span class="st">"0"</span> <span class="st">"0"</span></span>
<span id="cb35-9"><a href="#cb35-9" tabindex="-1"></a> <span class="sc">$</span> LikeCount            <span class="sc">:</span> chr  <span class="st">"0"</span> <span class="st">"0"</span> <span class="st">"0"</span> <span class="st">"0"</span></span>
<span id="cb35-10"><a href="#cb35-10" tabindex="-1"></a> <span class="sc">$</span> PublishedAt          <span class="sc">:</span> chr  <span class="st">"2020-01-10T02:23:43"</span> <span class="st">"2020-01-09T20:56:23"</span></span>
<span id="cb35-11"><a href="#cb35-11" tabindex="-1"></a>                               <span class="st">"2020-01-09T20:44:00"</span> <span class="st">"2020-01-09T19:31:32"</span> </span>
<span id="cb35-12"><a href="#cb35-12" tabindex="-1"></a> <span class="sc">$</span> UpdatedAt            <span class="sc">:</span> chr  <span class="st">"2020-01-10T02:23:43"</span> <span class="st">"2020-01-09T20:56:23"</span></span>
<span id="cb35-13"><a href="#cb35-13" tabindex="-1"></a>                               <span class="st">"2020-01-09T20:44:00"</span> <span class="st">"2020-01-09T19:31:32"</span></span>
<span id="cb35-14"><a href="#cb35-14" tabindex="-1"></a> <span class="sc">$</span> CommentID            <span class="sc">:</span> chr  <span class="st">"xx"</span> <span class="st">"xx"</span> <span class="st">"xx"</span> <span class="st">"xx"</span></span>
<span id="cb35-15"><a href="#cb35-15" tabindex="-1"></a> <span class="sc">$</span> ParentID             <span class="sc">:</span> chr  <span class="cn">NA</span> <span class="cn">NA</span> <span class="cn">NA</span> <span class="cn">NA</span></span>
<span id="cb35-16"><a href="#cb35-16" tabindex="-1"></a> <span class="sc">$</span> VideoID              <span class="sc">:</span> chr  <span class="st">"pJ_NyLQ"</span> <span class="st">"pJ_NyLQ"</span> <span class="st">"pJ_NyLQ"</span> <span class="st">"pJ_NyLQ"</span></span></code></pre></div>
<div class="section level4">
<h4 id="importing-saved-collection-data-from-file">Importing saved collection data from file<a class="anchor" aria-label="anchor" href="#importing-saved-collection-data-from-file"></a>
</h4>
<p>If you are reading a previously saved <code>writeToFile</code>
YouTube dataframe from disk, you simply need to use the
<code>readRDS</code> function:</p>
<div class="sourceCode" id="cb36"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># read dataframe from file</span></span>
<span><span class="va">youtubeData</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">readRDS</a></span><span class="op">(</span><span class="st">"2020-09-26_095354-YoutubeData.rds"</span><span class="op">)</span></span></code></pre></div>
</div>
</div>
<div class="section level3">
<h3 id="creating-youtube-networks">Creating YouTube Networks<a class="anchor" aria-label="anchor" href="#creating-youtube-networks"></a>
</h3>
<p>It is currently possible to create two types of networks using
YouTube data: (1) <em>actor network</em> and (2) <em>activity
network</em>.</p>
<div class="section level4">
<h4 id="actor-network-1">Actor Network<a class="anchor" aria-label="anchor" href="#actor-network-1"></a>
</h4>
<p>In the YouTube <em>actor network</em> the nodes are users who have
commented on videos (and the videos themselves are included in the
network as special nodes) and the edges are the interactions between
users in the comments. We can distinguish a <em>top-level comment</em>,
which is a comment that is directed to a video from a <em>reply
comment</em>, which is a comment directed to a top-level comment. The
YouTube user interface does not allow a user to direct a reply to
another reply. However, users can achieve the “reply to a reply”
functionality by starting their comment with the username of the person
that they are replying to (and they often prepend the username with
“@”). So there will be an edge from user <em>i</em> to user <em>j</em>
if <em>i</em> replied to a top-level comment authored by <em>j</em> or
else <em>i</em> prepended their comment with <em>j</em>’s username.</p>
<div class="sourceCode" id="cb37"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">actorNetwork</span> <span class="op">&lt;-</span> <span class="va">youtubeData</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"actor"</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/AddText.html">AddText</a></span><span class="op">(</span><span class="va">youtubeData</span><span class="op">)</span></span>
<span><span class="va">actorGraph</span> <span class="op">&lt;-</span> <span class="va">actorNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span>writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p><code>Create("actor")</code> returns a named list containing two
dataframes named “nodes” and “edges” (the following has been modified to
preserve anonymity):</p>
<div class="sourceCode" id="cb38"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb38-1"><a href="#cb38-1" tabindex="-1"></a><span class="sc">&gt;</span> actorNetwork</span>
<span id="cb38-2"><a href="#cb38-2" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb38-3"><a href="#cb38-3" tabindex="-1"></a><span class="co"># A tibble: 522 x 3</span></span>
<span id="cb38-4"><a href="#cb38-4" tabindex="-1"></a>   id                       screen_name                         node_type</span>
<span id="cb38-5"><a href="#cb38-5" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>                    <span class="er">&lt;</span>chr<span class="sc">&gt;</span>                               <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb38-6"><a href="#cb38-6" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxxx                      actor</span>
<span id="cb38-7"><a href="#cb38-7" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxx                       actor</span>
<span id="cb38-8"><a href="#cb38-8" tabindex="-1"></a>[snip]</span>
<span id="cb38-9"><a href="#cb38-9" tabindex="-1"></a><span class="co"># … with 512 more rows</span></span>
<span id="cb38-10"><a href="#cb38-10" tabindex="-1"></a></span>
<span id="cb38-11"><a href="#cb38-11" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb38-12"><a href="#cb38-12" tabindex="-1"></a><span class="co"># A tibble: 604 x 6</span></span>
<span id="cb38-13"><a href="#cb38-13" tabindex="-1"></a>   from      to       video_id comment_id   edge_type vosonTxt_comment</span>
<span id="cb38-14"><a href="#cb38-14" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>chr<span class="sc">&gt;</span>    <span class="er">&lt;</span>chr<span class="sc">&gt;</span>    <span class="er">&lt;</span>chr<span class="sc">&gt;</span>        <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb38-15"><a href="#cb38-15" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxx… VIDEOID… pJ_NyEY… xxxxxxxxxxx… comment   <span class="st">"xxxxx"</span></span>
<span id="cb38-16"><a href="#cb38-16" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxx… VIDEOID… pJ_NyEY… xxxxxxxxxxx… comment   <span class="st">"xxxxx"</span></span>
<span id="cb38-17"><a href="#cb38-17" tabindex="-1"></a>[snip]</span>
<span id="cb38-18"><a href="#cb38-18" tabindex="-1"></a><span class="co"># … with 594 more rows</span></span>
<span id="cb38-19"><a href="#cb38-19" tabindex="-1"></a></span>
<span id="cb38-20"><a href="#cb38-20" tabindex="-1"></a><span class="fu">attr</span>(,<span class="st">"class"</span>)</span>
<span id="cb38-21"><a href="#cb38-21" tabindex="-1"></a>[<span class="dv">1</span>] <span class="st">"list"</span>       <span class="st">"network"</span>    <span class="st">"actor"</span>      <span class="st">"youtube"</span>    <span class="st">"voson_text"</span></span></code></pre></div>
<p>Note that in the above, <code><a href="../reference/AddText.html">AddText()</a></code> was used to add the
comment text data to the network dataframe, stored as an edge attribute.
Also, note that there is an optional parameter
<code>replies_from_text</code> that can be passed to
<code><a href="../reference/AddText.html">AddText()</a></code> when used with YouTube network creation, to
extract the “reply to reply” comments.</p>
<p>This list is then passed to <code><a href="../reference/Graph.html">Graph()</a></code>, which returns an
<code>igraph</code> graph object. Remember that it is possible to
achieve the above using a single line of code:</p>
<div class="sourceCode" id="cb39"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">actorGraph</span> <span class="op">&lt;-</span> <span class="va">youtubeData</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"actor"</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/AddText.html">AddText</a></span><span class="op">(</span><span class="va">youtubeData</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p>The following is an an annonymised summary of the <code>igraph</code>
graph object.</p>
<div class="sourceCode" id="cb40"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb40-1"><a href="#cb40-1" tabindex="-1"></a><span class="sc">&gt;</span> actorGraph</span>
<span id="cb40-2"><a href="#cb40-2" tabindex="-1"></a>IGRAPH <span class="fl">79e5456</span> DN<span class="sc">--</span> <span class="dv">522</span> <span class="dv">604</span> <span class="sc">--</span></span>
<span id="cb40-3"><a href="#cb40-3" tabindex="-1"></a><span class="sc">+</span> attr<span class="sc">:</span> <span class="fu">type</span> (g<span class="sc">/</span>c), <span class="fu">name</span> (v<span class="sc">/</span>c), <span class="fu">screen_name</span> (v<span class="sc">/</span>c), <span class="fu">node_type</span> (v<span class="sc">/</span>c),</span>
<span id="cb40-4"><a href="#cb40-4" tabindex="-1"></a><span class="sc">|</span> <span class="fu">label</span> (v<span class="sc">/</span>c), <span class="fu">video_id</span> (e<span class="sc">/</span>c), <span class="fu">comment_id</span> (e<span class="sc">/</span>c), <span class="fu">edge_type</span> (e<span class="sc">/</span>c),</span>
<span id="cb40-5"><a href="#cb40-5" tabindex="-1"></a><span class="sc">|</span> <span class="fu">vosonTxt_comment</span> (e<span class="sc">/</span>c)</span>
<span id="cb40-6"><a href="#cb40-6" tabindex="-1"></a><span class="sc">+</span> edges from <span class="fl">79e5456</span> (vertex names)<span class="sc">:</span></span>
<span id="cb40-7"><a href="#cb40-7" tabindex="-1"></a>[<span class="dv">1</span>] xxxx<span class="ot">-&gt;</span>VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ</span>
<span id="cb40-8"><a href="#cb40-8" tabindex="-1"></a>[<span class="dv">2</span>] xxxx<span class="ot">-&gt;</span>VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ</span>
<span id="cb40-9"><a href="#cb40-9" tabindex="-1"></a>[snip]</span>
<span id="cb40-10"><a href="#cb40-10" tabindex="-1"></a><span class="sc">+</span> ... omitted several edges</span></code></pre></div>
<p>The YouTube actor network node contains a graph attribute
<code>type</code> (set to “youtube”). The node attributes are:
<code>name</code> (Channel ID, which is YouTube’s unique user ID),
<code>screen_name</code> (the users displayed name),
<code>node_type</code> (‘actor’ or ‘video’) and <code>label</code> (a
concatenation of the ID and screen name). The edge attributes are:
<code>video_id</code> (the ID of the video for which the data have been
collected), <code>comment_id</code> (the ID of the comment),
<code>edge_type</code> (whether the edge is a ‘comment’ i.e. top-level
comment, ‘reply-comment’ i.e. reply to top-level comment or reply to
reply or ‘self-loop’, which is a special edge connecting the video to
itself, as a means of including text posted with the video). In the
above example, because of our earlier use of <code><a href="../reference/AddText.html">AddText()</a></code>,
there is also an edge attribute <code>vosonTxt_comment</code> which is
the text associated with the comment, reply or video.</p>
<p>The example YouTube actor network contains 522 nodes and 604 edges.
The following indicates that there were 500 top-level comments (we
constrained the collection to this number), 103 replies to top-level
comments (note: we did not use <code><a href="../reference/AddText.html">AddText()</a></code> to collect replies
embedded within the text), and there is the single self-loop from the
video to itself.</p>
<div class="sourceCode" id="cb41"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb41-1"><a href="#cb41-1" tabindex="-1"></a><span class="sc">&gt;</span> <span class="fu">table</span>(<span class="fu">E</span>(actorGraph)<span class="sc">$</span>edge_type)</span>
<span id="cb41-2"><a href="#cb41-2" tabindex="-1"></a>   comment reply<span class="sc">-</span>comment     self<span class="sc">-</span>loop</span>
<span id="cb41-3"><a href="#cb41-3" tabindex="-1"></a>       <span class="dv">500</span>           <span class="dv">103</span>             <span class="dv">1</span></span></code></pre></div>
<p>We can visualize this network, using red to identify the video
nodes.</p>
<div class="sourceCode" id="cb42"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># change color of nodes with type video to red and others grey</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">actorGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/ifelse.html" class="external-link">ifelse</a></span><span class="op">(</span></span>
<span>  <span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">actorGraph</span><span class="op">)</span><span class="op">$</span><span class="va">node_type</span> <span class="op">==</span> <span class="st">"video"</span>, <span class="st">"red"</span>, <span class="st">"grey"</span></span>
<span><span class="op">)</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"youtube_actor.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">actorGraph</span>, vertex.label <span class="op">=</span> <span class="st">""</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>, edge.arrow.size <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/youtube_actor.png" alt="YouTube actor network (red node is video)"><div class="figcaption">YouTube actor network (red node is video)</div>
</div>
<p>The following creates a sub-network containing only the replies to
top-level comments. In removing the other edges (top-level comments and
the self-loop) we create a number isolate nodes (nodes with no
connections) that we also remove. We have also used red to indicate the
people who have written comments containing particular terms that have
been present in the online commentary about the bushfires.</p>
<div class="sourceCode" id="cb43"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb43-1"><a href="#cb43-1" tabindex="-1"></a><span class="co"># removed edges that are not of type reply-comment</span></span>
<span id="cb43-2"><a href="#cb43-2" tabindex="-1"></a>g2 <span class="ot">&lt;-</span> <span class="fu">delete.edges</span>(</span>
<span id="cb43-3"><a href="#cb43-3" tabindex="-1"></a>  actorGraph, <span class="fu">which</span>(<span class="fu">E</span>(actorGraph)<span class="sc">$</span>edge_type <span class="sc">!=</span> <span class="st">"reply-comment"</span>)</span>
<span id="cb43-4"><a href="#cb43-4" tabindex="-1"></a>)</span>
<span id="cb43-5"><a href="#cb43-5" tabindex="-1"></a></span>
<span id="cb43-6"><a href="#cb43-6" tabindex="-1"></a><span class="co"># check number of isolates</span></span>
<span id="cb43-7"><a href="#cb43-7" tabindex="-1"></a><span class="sc">&gt;</span> <span class="fu">length</span>(<span class="fu">which</span>(<span class="fu">degree</span>(g2) <span class="sc">==</span> <span class="dv">0</span>))</span>
<span id="cb43-8"><a href="#cb43-8" tabindex="-1"></a>[<span class="dv">1</span>] <span class="dv">417</span></span>
<span id="cb43-9"><a href="#cb43-9" tabindex="-1"></a></span>
<span id="cb43-10"><a href="#cb43-10" tabindex="-1"></a><span class="co"># remove isolates</span></span>
<span id="cb43-11"><a href="#cb43-11" tabindex="-1"></a>g2 <span class="ot">&lt;-</span> <span class="fu">delete.vertices</span>(g2, <span class="fu">which</span>(<span class="fu">degree</span>(g2) <span class="sc">==</span> <span class="dv">0</span>))</span>
<span id="cb43-12"><a href="#cb43-12" tabindex="-1"></a></span>
<span id="cb43-13"><a href="#cb43-13" tabindex="-1"></a><span class="co"># get node indexes for the tails of edges that have comments containing</span></span>
<span id="cb43-14"><a href="#cb43-14" tabindex="-1"></a><span class="co"># words of interest change the indexed node colors to red and others grey</span></span>
<span id="cb43-15"><a href="#cb43-15" tabindex="-1"></a><span class="fu">V</span>(g2)<span class="sc">$</span>color <span class="ot">&lt;-</span> <span class="st">"grey"</span></span>
<span id="cb43-16"><a href="#cb43-16" tabindex="-1"></a>ind <span class="ot">&lt;-</span> <span class="fu">tail_of</span>(</span>
<span id="cb43-17"><a href="#cb43-17" tabindex="-1"></a>  actorGraph,</span>
<span id="cb43-18"><a href="#cb43-18" tabindex="-1"></a>  <span class="fu">grep</span>(<span class="st">"arson|backburn|climate change"</span>, <span class="fu">tolower</span>(<span class="fu">E</span>(g2)<span class="sc">$</span>vosonTxt_comment))</span>
<span id="cb43-19"><a href="#cb43-19" tabindex="-1"></a>)</span>
<span id="cb43-20"><a href="#cb43-20" tabindex="-1"></a><span class="fu">V</span>(g2)<span class="sc">$</span>color[ind] <span class="ot">&lt;-</span> <span class="st">"red"</span></span>
<span id="cb43-21"><a href="#cb43-21" tabindex="-1"></a></span>
<span id="cb43-22"><a href="#cb43-22" tabindex="-1"></a><span class="co"># open and write plot to a png file</span></span>
<span id="cb43-23"><a href="#cb43-23" tabindex="-1"></a><span class="fu">png</span>(<span class="st">"youtube_actor_reply.png"</span>, <span class="at">width =</span> <span class="dv">600</span>, <span class="at">height =</span> <span class="dv">600</span>)</span>
<span id="cb43-24"><a href="#cb43-24" tabindex="-1"></a><span class="fu">plot</span>(g2, <span class="at">vertex.label =</span> <span class="st">""</span>, <span class="at">vertex.size =</span> <span class="dv">4</span>, <span class="at">edge.arrow.size =</span> <span class="fl">0.5</span>)</span>
<span id="cb43-25"><a href="#cb43-25" tabindex="-1"></a><span class="fu">dev.off</span>()</span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/youtube_actor_reply.png" alt="YouTube actor network - only actors sending or receiving replies"><div class="figcaption">YouTube actor network - only actors sending or
receiving replies</div>
</div>
<p>Finally, the <code><a href="../reference/AddVideoData.html">AddVideoData()</a></code> function supplements the
network data with additional video information.</p>
<div class="sourceCode" id="cb44"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">actorNetwork_withVideoInfo</span> <span class="op">&lt;-</span> <span class="va">actorNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/AddVideoData.html">AddVideoData</a></span><span class="op">(</span><span class="va">youtubeAuth</span><span class="op">)</span></span></code></pre></div>
<p><code><a href="../reference/AddVideoData.html">AddVideoData()</a></code> returns a named list containing three
dataframes named “nodes” (identical to the dataframe contained in the
list <code>actorNetwork</code> in the example able), “edges” (this has
three additional columns: “video_title”, “video_description”,
“video_published_at”) and a new dataframe “videos” (the following has
been modified to preserve anonymity):</p>
<div class="sourceCode" id="cb45"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb45-1"><a href="#cb45-1" tabindex="-1"></a><span class="sc">&gt;</span> actorNetwork_withVideoInfo</span>
<span id="cb45-2"><a href="#cb45-2" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb45-3"><a href="#cb45-3" tabindex="-1"></a><span class="co"># A tibble: 522 x 3</span></span>
<span id="cb45-4"><a href="#cb45-4" tabindex="-1"></a>   id                       screen_name                         node_type</span>
<span id="cb45-5"><a href="#cb45-5" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>                    <span class="er">&lt;</span>chr<span class="sc">&gt;</span>                               <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb45-6"><a href="#cb45-6" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxx                       actor</span>
<span id="cb45-7"><a href="#cb45-7" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxxxxxxxxxxxxxxxxxx xxxxxxxxxxxxx                       actor</span>
<span id="cb45-8"><a href="#cb45-8" tabindex="-1"></a>[snip]</span>
<span id="cb45-9"><a href="#cb45-9" tabindex="-1"></a><span class="co"># … with 512 more rows</span></span>
<span id="cb45-10"><a href="#cb45-10" tabindex="-1"></a></span>
<span id="cb45-11"><a href="#cb45-11" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb45-12"><a href="#cb45-12" tabindex="-1"></a><span class="co"># A tibble: 604 x 9</span></span>
<span id="cb45-13"><a href="#cb45-13" tabindex="-1"></a>   from  to    video_id comment_id edge_type vosonTxt_comment video_title</span>
<span id="cb45-14"><a href="#cb45-14" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span>    <span class="er">&lt;</span>chr<span class="sc">&gt;</span>      <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>chr<span class="sc">&gt;</span>            <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb45-15"><a href="#cb45-15" tabindex="-1"></a> <span class="dv">1</span> xxxx… xxxx… pJ_NyEY… xxxxxxxxx… comment   xxxxxxxxxxxx … Australia …</span>
<span id="cb45-16"><a href="#cb45-16" tabindex="-1"></a> <span class="dv">2</span> xxxx… xxxx… pJ_NyEY… xxxxxxxxx… comment   <span class="st">"xxxx"</span>         Australia …</span>
<span id="cb45-17"><a href="#cb45-17" tabindex="-1"></a>[snip]</span>
<span id="cb45-18"><a href="#cb45-18" tabindex="-1"></a><span class="co"># … with 594 more rows, and 2 more variables: video_description &lt;chr&gt;,</span></span>
<span id="cb45-19"><a href="#cb45-19" tabindex="-1"></a><span class="co">#   video_published_at &lt;chr&gt;</span></span>
<span id="cb45-20"><a href="#cb45-20" tabindex="-1"></a></span>
<span id="cb45-21"><a href="#cb45-21" tabindex="-1"></a><span class="sc">$</span>videos</span>
<span id="cb45-22"><a href="#cb45-22" tabindex="-1"></a><span class="co"># A tibble: 1 x 6</span></span>
<span id="cb45-23"><a href="#cb45-23" tabindex="-1"></a> VideoID  VideoTitle  VideoDescription VideoPublishedAt ChannelID ChannelTitle</span>
<span id="cb45-24"><a href="#cb45-24" tabindex="-1"></a> <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>    <span class="er">&lt;</span>chr<span class="sc">&gt;</span>       <span class="er">&lt;</span>chr<span class="sc">&gt;</span>            <span class="er">&lt;</span>chr<span class="sc">&gt;</span>            <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb45-25"><a href="#cb45-25" tabindex="-1"></a><span class="dv">1</span> pJ_NyEY… Australia … <span class="st">"As Australia ba… 2020-01-05T12:3… UCknLrEd… DW News</span></span>
<span id="cb45-26"><a href="#cb45-26" tabindex="-1"></a></span>
<span id="cb45-27"><a href="#cb45-27" tabindex="-1"></a><span class="st">attr(,"</span>class<span class="st">")</span></span>
<span id="cb45-28"><a href="#cb45-28" tabindex="-1"></a><span class="st">[1] "</span>list<span class="st">"             "</span>network<span class="st">"          "</span>actor<span class="st">"            "</span>youtube<span class="st">"</span></span>
<span id="cb45-29"><a href="#cb45-29" tabindex="-1"></a><span class="st">[5] "</span>voson_text<span class="st">"       "</span>voson_video_data<span class="st">"</span></span></code></pre></div>
<p>It should also be noted that <code><a href="../reference/AddVideoData.html">AddVideoData()</a></code> can
optionally substitute references to the video ID in the “nodes” and
“edges” dataframes with the video publishers channel ID (this is done by
setting the parameter <code>actorSubOnly</code> to TRUE.</p>
</div>
<div class="section level4">
<h4 id="activity-network-1">Activity Network<a class="anchor" aria-label="anchor" href="#activity-network-1"></a>
</h4>
<p>In the YouTube <em>activity network</em>, nodes are either comments
or videos (videos represent a starting comment).</p>
<div class="sourceCode" id="cb46"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">activityNetwork</span> <span class="op">&lt;-</span> <span class="va">youtubeData</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"activity"</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/AddText.html">AddText</a></span><span class="op">(</span><span class="va">youtubeData</span><span class="op">)</span></span>
<span><span class="va">activityGraph</span> <span class="op">&lt;-</span> <span class="va">activityNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<p><code>Create("activity")</code> returns a named list containing two
dataframes named “nodes” and “edges” (the following has been modified to
preserve anonymity).</p>
<div class="sourceCode" id="cb47"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb47-1"><a href="#cb47-1" tabindex="-1"></a><span class="sc">&gt;</span> activityNetwork</span>
<span id="cb47-2"><a href="#cb47-2" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb47-3"><a href="#cb47-3" tabindex="-1"></a><span class="co"># A tibble: 603 x 3</span></span>
<span id="cb47-4"><a href="#cb47-4" tabindex="-1"></a>   from                       to                  edge_type</span>
<span id="cb47-5"><a href="#cb47-5" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>                      <span class="er">&lt;</span>chr<span class="sc">&gt;</span>               <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb47-6"><a href="#cb47-6" tabindex="-1"></a> <span class="dv">1</span> xxxxxxxxxxxxxxxxxxxxxxxxxx VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ comment</span>
<span id="cb47-7"><a href="#cb47-7" tabindex="-1"></a> <span class="dv">2</span> xxxxxxxxxxxxxxxxxxxxxxxxxx VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ comment</span>
<span id="cb47-8"><a href="#cb47-8" tabindex="-1"></a>[snip]</span>
<span id="cb47-9"><a href="#cb47-9" tabindex="-1"></a><span class="co"># … with 593 more rows</span></span>
<span id="cb47-10"><a href="#cb47-10" tabindex="-1"></a></span>
<span id="cb47-11"><a href="#cb47-11" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb47-12"><a href="#cb47-12" tabindex="-1"></a><span class="co"># A tibble: 604 x 8</span></span>
<span id="cb47-13"><a href="#cb47-13" tabindex="-1"></a>   id    video_id published_at updated_at author_id screen_name node_type</span>
<span id="cb47-14"><a href="#cb47-14" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span>    <span class="er">&lt;</span>chr<span class="sc">&gt;</span>        <span class="er">&lt;</span>chr<span class="sc">&gt;</span>      <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>chr<span class="sc">&gt;</span>       <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb47-15"><a href="#cb47-15" tabindex="-1"></a> <span class="dv">1</span> xxxx… pJ_NyEY… <span class="dv">2020-01-10</span>T… <span class="dv">2020-01-1</span>… xxxxxxxx… xxxxxxxxxx… comment</span>
<span id="cb47-16"><a href="#cb47-16" tabindex="-1"></a> <span class="dv">2</span> xxxx… pJ_NyEY… <span class="dv">2020-01-09</span>T… <span class="dv">2020-01-0</span>… xxxxxxxx… xxxxxxxxxx… comment</span>
<span id="cb47-17"><a href="#cb47-17" tabindex="-1"></a>[snip]</span>
<span id="cb47-18"><a href="#cb47-18" tabindex="-1"></a><span class="co"># … with 594 more rows, and 1 more variable: vosonTxt_comment &lt;chr&gt;</span></span>
<span id="cb47-19"><a href="#cb47-19" tabindex="-1"></a></span>
<span id="cb47-20"><a href="#cb47-20" tabindex="-1"></a><span class="fu">attr</span>(,<span class="st">"class"</span>)</span>
<span id="cb47-21"><a href="#cb47-21" tabindex="-1"></a>[<span class="dv">1</span>] <span class="st">"list"</span>       <span class="st">"network"</span>    <span class="st">"activity"</span>   <span class="st">"youtube"</span>    <span class="st">"voson_text"</span></span></code></pre></div>
<p>Note that in the above, <code><a href="../reference/AddText.html">AddText()</a></code> was used to add the
comment text data to the network dataframe, stored as a node attribute.
This list is then passed to <code><a href="../reference/Graph.html">Graph()</a></code>, which returns an
<code>igraph</code> graph object (this has been anonymised).</p>
<div class="sourceCode" id="cb48"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb48-1"><a href="#cb48-1" tabindex="-1"></a>IGRAPH <span class="dv">02664</span>d1 DN<span class="sc">--</span> <span class="dv">604</span> <span class="dv">603</span> <span class="sc">--</span></span>
<span id="cb48-2"><a href="#cb48-2" tabindex="-1"></a><span class="sc">+</span> attr<span class="sc">:</span> <span class="fu">type</span> (g<span class="sc">/</span>c), <span class="fu">name</span> (v<span class="sc">/</span>c), <span class="fu">video_id</span> (v<span class="sc">/</span>c), <span class="fu">published_at</span> (v<span class="sc">/</span>c),</span>
<span id="cb48-3"><a href="#cb48-3" tabindex="-1"></a><span class="sc">|</span> <span class="fu">updated_at</span> (v<span class="sc">/</span>c), <span class="fu">author_id</span> (v<span class="sc">/</span>c), <span class="fu">screen_name</span> (v<span class="sc">/</span>c), node_type</span>
<span id="cb48-4"><a href="#cb48-4" tabindex="-1"></a><span class="sc">|</span> (v<span class="sc">/</span>c), <span class="fu">vosonTxt_comment</span> (v<span class="sc">/</span>c), <span class="fu">label</span> (v<span class="sc">/</span>c), <span class="fu">edge_type</span> (e<span class="sc">/</span>c)</span>
<span id="cb48-5"><a href="#cb48-5" tabindex="-1"></a><span class="sc">+</span> edges from <span class="dv">02664</span><span class="fu">d1</span> (vertex names)<span class="sc">:</span></span>
<span id="cb48-6"><a href="#cb48-6" tabindex="-1"></a>[<span class="dv">1</span>] xxxx<span class="ot">-&gt;</span>VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ</span>
<span id="cb48-7"><a href="#cb48-7" tabindex="-1"></a>[<span class="dv">2</span>] xxxx<span class="ot">-&gt;</span>VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ</span>
<span id="cb48-8"><a href="#cb48-8" tabindex="-1"></a>[<span class="dv">3</span>] xxxx<span class="ot">-&gt;</span>VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ</span>
<span id="cb48-9"><a href="#cb48-9" tabindex="-1"></a>[<span class="dv">4</span>] xxxx<span class="ot">-&gt;</span>VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ</span>
<span id="cb48-10"><a href="#cb48-10" tabindex="-1"></a>[<span class="dv">5</span>] xxxx<span class="ot">-&gt;</span>VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ</span>
<span id="cb48-11"><a href="#cb48-11" tabindex="-1"></a>[<span class="dv">6</span>] xxxx<span class="ot">-&gt;</span>VIDEOID<span class="sc">:</span>pJ_NyEYRkLQ</span>
<span id="cb48-12"><a href="#cb48-12" tabindex="-1"></a><span class="sc">+</span> ... omitted several edges</span></code></pre></div>
<p>The YouTube activity network contains a graph attribute
<code>type</code> (set to “youtube”). The node attributes are:
<code>name</code> (character string ID number for the comment or video),
<code>video_id</code> (character string ID of the video for which the
comments collected - in this example, “pJ_NyEYRkLQ”),
<code>published_at</code> (timestamp of when the comment was published,
this is <code>NA</code> for the video itself), <code>updated_at</code>
(timestamp of when a comment was updated), <code>author_id</code>
(user’s Channel ID), <code>screen_name</code> (user’s display name),
<code>node_type</code> (whether the node is a ‘comment’ i.e. top-level
comment, ‘reply-comment’ i.e. reply to top-level comment or reply to
reply or ‘video’), <code>vosonText_comment</code> (the comment text,
<code>NA</code> for the video), <code>label</code> (concatenation of
<code>name</code> and <code>screen_name</code>). The edge attributes
<code>edge_type</code> which is ‘comment’ for all edges connecting a
top-level comment to the video, and ‘reply-comment’ for all other
edges.</p>
<p>The example YouTube activity network contains 604 nodes and 603
edges. The following is an <code>igraph</code> visualization of the
network, where the video is indicated by a red node, and blue indicates
comments that include one of the following terms: “arson”, “bakcburn”,
“climate change”.</p>
<div class="sourceCode" id="cb49"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># set all video node colors to red and others to grey</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span> <span class="op">&lt;-</span> <span class="st">"grey"</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">node_type</span> <span class="op">==</span> <span class="st">"video"</span><span class="op">)</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"red"</span></span>
<span></span>
<span><span class="co"># get node indexes of comments that contain terms of interest</span></span>
<span><span class="co"># set their node colors to blue</span></span>
<span><span class="va">ind</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/grep.html" class="external-link">grep</a></span><span class="op">(</span></span>
<span>  <span class="st">"arson|backburn|climate change"</span>, <span class="fu"><a href="https://rdrr.io/r/base/chartr.html" class="external-link">tolower</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">vosonTxt_comment</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span><span class="op">[</span><span class="va">ind</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"blue"</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"youtube_activity.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">activityGraph</span>, vertex.label <span class="op">=</span> <span class="st">""</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>, edge.arrow.size <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/youtube_activity.png" alt="YouTube activity network (red node is video, blue nodes are comments mentioning particular terms)"><div class="figcaption">YouTube activity network (red node is video,
blue nodes are comments mentioning particular terms)</div>
</div>
</div>
</div>
</div>
<div class="section level2">
<h2 id="reddit">Reddit<a class="anchor" aria-label="anchor" href="#reddit"></a>
</h2>
<p>The Reddit collection in <code>vosonSML</code> is based on the
approach used in the <a href="https://cran.r-project.org/package=RedditExtractoR" class="external-link">RedditExtractoR</a>
package.</p>
<div class="section level3">
<h3 id="authenticating-with-the-reddit-api">Authenticating with the Reddit API<a class="anchor" aria-label="anchor" href="#authenticating-with-the-reddit-api"></a>
</h3>
<p>The <code>vosonSML</code> does not require Reddit API credentials to
be provided. However, to keep the workflow consistent with the other
data sources, we still need to create a “dummy” access token, using the
<code><a href="../reference/Authenticate.html">Authenticate()</a></code> function (see below).</p>
</div>
<div class="section level3">
<h3 id="collecting-data-from-reddit">Collecting Data from Reddit<a class="anchor" aria-label="anchor" href="#collecting-data-from-reddit"></a>
</h3>
<p>To collect Reddit comment data, first construct a character vector
containing the post URL(s).</p>
<div class="sourceCode" id="cb50"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">myThreadUrls</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/c.html" class="external-link">c</a></span><span class="op">(</span></span>
<span>  <span class="st">"https://www.reddit.com/r/xxxxxx/comments/xxxxxx/x_xxxx_xxxxxxxxx/"</span>,</span>
<span>  <span class="st">"https://www.reddit.com/r/xxxxxx/comments/xxxxxx/x_xxxx_xxxxxxxxx/"</span></span>
<span><span class="op">)</span></span></code></pre></div>
<p>This character vector is then passed as an argument to the
<code><a href="../reference/Collect.html">Collect()</a></code> function. In the example below, a post relating
to the politics around the Australian bushfires was used: <a href="https://www.reddit.com/r/worldnews/comments/elcb9b/australias_leaders_deny_link_between_climate/" class="external-link uri">https://www.reddit.com/r/worldnews/comments/elcb9b/australias_leaders_deny_link_between_climate/</a>.
This post was created on 7th January 2020 and by the time of data
collection (10th January), it had attracted over 4000 comments. The
maximum number of comments available for retrieval is 500 per thread or
post.</p>
<p>Reddit has implemented a feature in their latest site re-design to
branch off into new threads, when a thread reaches a breadth (diameter)
of 10 comments. These appear as ‘Continue this thread’ links in thread
discussions on the reddit site, and as new listing markers within the
collected thread data. <code>vosonSML</code> follows these links with
additional thread requests and collects comments from those as well,
capturing a more complete data set, as the limit of 500 comments applies
to each ‘new’ thread.</p>
<div class="sourceCode" id="cb51"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">myThreadUrls</span> <span class="op">&lt;-</span> <span class="st">"https://www.reddit.com/r/worldnews/comments/elcb9b/australias_leaders_deny_link_between_climate/"</span></span>
<span><span class="va">redditData</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Authenticate.html">Authenticate</a></span><span class="op">(</span><span class="st">"reddit"</span><span class="op">)</span> <span class="op">|&gt;</span></span>
<span>              <span class="fu"><a href="../reference/Collect.html">Collect</a></span><span class="op">(</span>threadUrls <span class="op">=</span> <span class="va">myThreadUrls</span>, writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p>The <code><a href="../reference/Collect.html">Collect()</a></code> function takes the following arguments
(when used for collecting Reddit data): <code>credential</code> (an
object generated from <code><a href="../reference/Authenticate.html">Authenticate()</a></code> with class name
“reddit” (above we pass this via the pipe), <code>threadUrls</code>
(character vector of Reddit thread urls), <code>waitTime</code> (a
numeric vector giving the time range in seconds to select random wait
url collection requests; default is <code>c(3, 10)</code> i.e. random
wait between 3 and 10 seconds), <code>ua</code> (User-Agent string;
default is <code>option("HTTPUserAgent")</code> as set by vosonSML,
<code>writeToFile</code> (whether to write the returned dataframe to
file as an <code>.rds</code> file; default is FALSE),
<code>verbose</code> (whether to output information about the data
collection; default is TRUE).</p>
<p>The <code><a href="../reference/Collect.html">Collect()</a></code> function returns a <code>tibble</code>
dataframe (this output has been anonymised):</p>
<div class="sourceCode" id="cb52"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb52-1"><a href="#cb52-1" tabindex="-1"></a><span class="sc">&gt;</span> <span class="fu">str</span>(redditData)</span>
<span id="cb52-2"><a href="#cb52-2" tabindex="-1"></a>Classes ‘tbl_df’, ‘tbl’, ‘datasource’, ‘reddit’ and <span class="st">'data.frame'</span><span class="sc">:</span>   </span>
<span id="cb52-3"><a href="#cb52-3" tabindex="-1"></a>  <span class="dv">767</span> obs. of  <span class="dv">22</span> variables<span class="sc">:</span></span>
<span id="cb52-4"><a href="#cb52-4" tabindex="-1"></a> <span class="er">$</span> id              <span class="sc">:</span> int  <span class="dv">1</span> <span class="dv">2</span> <span class="dv">3</span> <span class="dv">4</span> <span class="dv">5</span> <span class="dv">6</span> <span class="dv">7</span> <span class="dv">8</span> <span class="dv">9</span> <span class="dv">10</span> ...</span>
<span id="cb52-5"><a href="#cb52-5" tabindex="-1"></a> <span class="sc">$</span> structure       <span class="sc">:</span> chr  <span class="st">"1"</span> <span class="st">"4_1_1_1_1_1_1_1_1_1"</span> <span class="st">"4_1_1_4_2_1_1_1_1_1"</span> ...</span>
<span id="cb52-6"><a href="#cb52-6" tabindex="-1"></a> <span class="sc">$</span> post_date       <span class="sc">:</span> chr  <span class="st">"2020-01-07 14:34:58"</span> <span class="st">"2020-01-07 14:34:58"</span> ...</span>
<span id="cb52-7"><a href="#cb52-7" tabindex="-1"></a> <span class="sc">$</span> post_date_unix  <span class="sc">:</span> num  <span class="fl">1.58e+09</span> <span class="fl">1.58e+09</span> <span class="fl">1.58e+09</span> <span class="fl">1.58e+09</span> <span class="fl">1.58e+09</span> ...</span>
<span id="cb52-8"><a href="#cb52-8" tabindex="-1"></a> <span class="sc">$</span> comm_id         <span class="sc">:</span> chr  <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> ...</span>
<span id="cb52-9"><a href="#cb52-9" tabindex="-1"></a> <span class="sc">$</span> comm_date       <span class="sc">:</span> chr  <span class="st">"2020-01-07 19:11:10"</span> <span class="st">"2020-01-07 21:04:05"</span> ...</span>
<span id="cb52-10"><a href="#cb52-10" tabindex="-1"></a> <span class="sc">$</span> comm_date_unix  <span class="sc">:</span> num  <span class="fl">1.58e+09</span> <span class="fl">1.58e+09</span> <span class="fl">1.58e+09</span> <span class="fl">1.58e+09</span> <span class="fl">1.58e+09</span> ...</span>
<span id="cb52-11"><a href="#cb52-11" tabindex="-1"></a> <span class="sc">$</span> num_comments    <span class="sc">:</span> int  <span class="dv">4435</span> <span class="dv">4435</span> <span class="dv">4435</span> <span class="dv">4435</span> <span class="dv">4435</span> <span class="dv">4435</span> <span class="dv">4435</span> <span class="dv">4435</span> <span class="dv">4435</span> <span class="dv">4435</span> ...</span>
<span id="cb52-12"><a href="#cb52-12" tabindex="-1"></a> <span class="sc">$</span> subreddit       <span class="sc">:</span> chr  <span class="st">"worldnews"</span> <span class="st">"worldnews"</span> <span class="st">"worldnews"</span> <span class="st">"worldnews"</span> ...</span>
<span id="cb52-13"><a href="#cb52-13" tabindex="-1"></a> <span class="sc">$</span> upvote_prop     <span class="sc">:</span> num  <span class="fl">0.91</span> <span class="fl">0.91</span> <span class="fl">0.91</span> <span class="fl">0.91</span> <span class="fl">0.91</span> <span class="fl">0.91</span> <span class="fl">0.91</span> <span class="fl">0.91</span> <span class="fl">0.91</span> <span class="fl">0.91</span> ...</span>
<span id="cb52-14"><a href="#cb52-14" tabindex="-1"></a> <span class="sc">$</span> post_score      <span class="sc">:</span> int  <span class="dv">45714</span> <span class="dv">45714</span> <span class="dv">45714</span> <span class="dv">45712</span> <span class="dv">45714</span> <span class="dv">45710</span> <span class="dv">45720</span> <span class="dv">45712</span> ..</span>
<span id="cb52-15"><a href="#cb52-15" tabindex="-1"></a> <span class="sc">$</span> author          <span class="sc">:</span> chr  <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> ...</span>
<span id="cb52-16"><a href="#cb52-16" tabindex="-1"></a> <span class="sc">$</span> user            <span class="sc">:</span> chr  <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> <span class="st">"xxxx"</span> ...</span>
<span id="cb52-17"><a href="#cb52-17" tabindex="-1"></a> <span class="sc">$</span> comment_score   <span class="sc">:</span> int  <span class="dv">1904</span> <span class="dv">136</span> <span class="dv">17</span> <span class="dv">13</span> <span class="dv">9</span> <span class="dv">9</span> <span class="dv">125</span> <span class="dv">4</span> <span class="dv">6</span> <span class="dv">12</span> ...</span>
<span id="cb52-18"><a href="#cb52-18" tabindex="-1"></a> <span class="sc">$</span> controversiality<span class="sc">:</span> int  <span class="dv">0</span> <span class="dv">0</span> <span class="dv">0</span> <span class="dv">0</span> <span class="dv">0</span> <span class="dv">0</span> <span class="dv">0</span> <span class="dv">0</span> <span class="dv">0</span> <span class="dv">0</span> ...</span>
<span id="cb52-19"><a href="#cb52-19" tabindex="-1"></a> <span class="sc">$</span> comment         <span class="sc">:</span> chr  <span class="st">"xxxx...</span></span>
<span id="cb52-20"><a href="#cb52-20" tabindex="-1"></a><span class="st"> $ title           : chr  "</span>Australia’s leaders deny link between climate change and the country’s devastating bushfires<span class="st">" "</span>Australia’s leaders deny link between climate change and the country’s devastating bushfires<span class="st">" "</span>Australia’s leaders deny link between climate change and the country’s devastating bushfires<span class="st">" "</span>Australia’s leaders deny link between climate change and the country’s devastating bushfires<span class="st">" ...</span></span>
<span id="cb52-21"><a href="#cb52-21" tabindex="-1"></a><span class="st"> $ post_text       : chr  "" "" "" "" ...</span></span>
<span id="cb52-22"><a href="#cb52-22" tabindex="-1"></a><span class="st"> $ link            : chr  "</span>https<span class="sc">:</span><span class="er">//</span>www.theglobeandmail.com<span class="sc">/</span>world<span class="sc">/</span>article<span class="sc">-</span>australias<span class="sc">-</span>leaders<span class="sc">-</span>unmoved<span class="sc">-</span>on<span class="sc">-</span>climate<span class="sc">-</span>action<span class="sc">-</span>after<span class="sc">-</span>devastating<span class="dv">-2</span><span class="sc">/</span><span class="st">" "</span>https<span class="sc">:</span><span class="er">//</span>www.theglobeandmail.com<span class="sc">/</span>world<span class="sc">/</span>article<span class="sc">-</span>australias<span class="sc">-</span>leaders<span class="sc">-</span>unmoved<span class="sc">-</span>on<span class="sc">-</span>climate<span class="sc">-</span>action<span class="sc">-</span>after<span class="sc">-</span>devastating<span class="dv">-2</span><span class="sc">/</span><span class="st">" "</span>https<span class="sc">:</span><span class="er">//</span>www.theglobeandmail.com<span class="sc">/</span>world<span class="sc">/</span>article<span class="sc">-</span>australias<span class="sc">-</span>leaders<span class="sc">-</span>unmoved<span class="sc">-</span>on<span class="sc">-</span>climate<span class="sc">-</span>action<span class="sc">-</span>after<span class="sc">-</span>devastating<span class="dv">-2</span><span class="sc">/</span><span class="st">" "</span>https<span class="sc">:</span><span class="er">//</span>www.theglobeandmail.com<span class="sc">/</span>world<span class="sc">/</span>article<span class="sc">-</span>australias<span class="sc">-</span>leaders<span class="sc">-</span>unmoved<span class="sc">-</span>on<span class="sc">-</span>climate<span class="sc">-</span>action<span class="sc">-</span>after<span class="sc">-</span>devastating<span class="dv">-2</span><span class="sc">/</span><span class="st">" ...</span></span>
<span id="cb52-23"><a href="#cb52-23" tabindex="-1"></a><span class="st"> $ domain          : chr  "</span>theglobeandmail.com<span class="st">" "</span>theglobeandmail.com<span class="st">" "</span>theglobeandmail.com<span class="st">" "</span>theglobeandmail.com<span class="st">" ...</span></span>
<span id="cb52-24"><a href="#cb52-24" tabindex="-1"></a><span class="st"> $ url             : chr  "</span>https<span class="sc">:</span><span class="er">//</span>www.reddit.com<span class="sc">/</span>r<span class="sc">/</span>worldnews<span class="sc">/</span>comments<span class="sc">/</span>elcb9b<span class="sc">/</span>australias_leaders_deny_link_between_climate<span class="sc">/</span><span class="st">" "</span>https<span class="sc">:</span><span class="er">//</span>www.reddit.com<span class="sc">/</span>r<span class="sc">/</span>worldnews<span class="sc">/</span>comments<span class="sc">/</span>elcb9b<span class="sc">/</span>australias_leaders_deny_link_between_climate<span class="sc">/</span><span class="st">" "</span>https<span class="sc">:</span><span class="er">//</span>www.reddit.com<span class="sc">/</span>r<span class="sc">/</span>worldnews<span class="sc">/</span>comments<span class="sc">/</span>elcb9b<span class="sc">/</span>australias_leaders_deny_link_between_climate<span class="sc">/</span><span class="st">" "</span>https<span class="sc">:</span><span class="er">//</span>www.reddit.com<span class="sc">/</span>r<span class="sc">/</span>worldnews<span class="sc">/</span>comments<span class="sc">/</span>elcb9b<span class="sc">/</span>australias_leaders_deny_link_between_climate<span class="sc">/</span><span class="st">" ...</span></span>
<span id="cb52-25"><a href="#cb52-25" tabindex="-1"></a><span class="st"> $ thread_id       : chr  "</span>elcb9b<span class="st">" "</span>elcb9b<span class="st">" "</span>elcb9b<span class="st">" "</span>elcb9b<span class="st">" ...</span></span></code></pre></div>
<div class="section level4">
<h4 id="importing-saved-collection-data-from-file-1">Importing saved collection data from file<a class="anchor" aria-label="anchor" href="#importing-saved-collection-data-from-file-1"></a>
</h4>
<p>If you are reading a previously saved <code>writeToFile</code> Reddit
dataframe from disk, you simply need to use the <code>readRDS</code>
function.</p>
<div class="sourceCode" id="cb53"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">redditData</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/readRDS.html" class="external-link">readRDS</a></span><span class="op">(</span><span class="st">"2020-09-26_095354-RedditData.rds"</span><span class="op">)</span></span></code></pre></div>
</div>
</div>
<div class="section level3">
<h3 id="creating-reddit-networks">Creating Reddit Networks<a class="anchor" aria-label="anchor" href="#creating-reddit-networks"></a>
</h3>
<p>It is currently possible to create two types of networks using Reddit
data: (1) <em>actor network</em> and (2) <em>activity network</em>.</p>
<div class="section level4">
<h4 id="actor-network-2">Actor Network<a class="anchor" aria-label="anchor" href="#actor-network-2"></a>
</h4>
<p>In the Reddit <em>actor network</em>, nodes represent users who have
posted original posts and comments and the edges are the interactions
between users in the comments i.e. where there is an edge from user
<em>i</em> to user <em>j</em> if <em>i</em> writes a comment that
replies to user <em>j</em>’s comment (or the original post).</p>
<p>The following creates a Reddit <em>actor network</em> with comment
text as an edge attribute (as above, this can be achieved in a single
line of code, but we split it into two lines to better explain the
objects that are created).</p>
<div class="sourceCode" id="cb54"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">actorNetwork</span> <span class="op">&lt;-</span> <span class="va">redditData</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"actor"</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/AddText.html">AddText</a></span><span class="op">(</span><span class="va">redditData</span><span class="op">)</span></span>
<span><span class="va">actorGraph</span> <span class="op">&lt;-</span> <span class="va">actorNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span>writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p><code>Create("actor")</code> returns a named list containing two
dataframes named “nodes” and “edges” (the following has been modified to
preserve anonymity):</p>
<div class="sourceCode" id="cb55"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb55-1"><a href="#cb55-1" tabindex="-1"></a><span class="sc">&gt;</span> actorNetwork</span>
<span id="cb55-2"><a href="#cb55-2" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb55-3"><a href="#cb55-3" tabindex="-1"></a><span class="co"># A tibble: 439 x 2</span></span>
<span id="cb55-4"><a href="#cb55-4" tabindex="-1"></a>      id user</span>
<span id="cb55-5"><a href="#cb55-5" tabindex="-1"></a>   <span class="sc">&lt;</span>int<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb55-6"><a href="#cb55-6" tabindex="-1"></a> <span class="dv">1</span>     <span class="dv">1</span> xxxxxxxxxx</span>
<span id="cb55-7"><a href="#cb55-7" tabindex="-1"></a> <span class="dv">2</span>     <span class="dv">2</span> xxxxxxxxxxxxxx</span>
<span id="cb55-8"><a href="#cb55-8" tabindex="-1"></a>[snip]</span>
<span id="cb55-9"><a href="#cb55-9" tabindex="-1"></a><span class="co"># … with 429 more rows</span></span>
<span id="cb55-10"><a href="#cb55-10" tabindex="-1"></a></span>
<span id="cb55-11"><a href="#cb55-11" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb55-12"><a href="#cb55-12" tabindex="-1"></a><span class="co"># A tibble: 768 x 8</span></span>
<span id="cb55-13"><a href="#cb55-13" tabindex="-1"></a>    from    to subreddit thread_id comment_id comm_id vosonTxt_comment   title</span>
<span id="cb55-14"><a href="#cb55-14" tabindex="-1"></a>   <span class="sc">&lt;</span>int<span class="sc">&gt;</span> <span class="er">&lt;</span>int<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>chr<span class="sc">&gt;</span>        <span class="er">&lt;</span>dbl<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span>   <span class="er">&lt;</span>chr<span class="sc">&gt;</span>                <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb55-15"><a href="#cb55-15" tabindex="-1"></a> <span class="dv">1</span>     <span class="dv">1</span>   <span class="dv">439</span> worldnews elcb9b           <span class="dv">1</span> xxxxxxx <span class="st">"xxxxxxxxxxxxxxxxxxx NA</span></span>
<span id="cb55-16"><a href="#cb55-16" tabindex="-1"></a><span class="st"> 2     2    73 worldnews elcb9b           2 xxxxxxx "</span>xxxxxxxxxxxxxxxxxxx <span class="cn">NA</span></span>
<span id="cb55-17"><a href="#cb55-17" tabindex="-1"></a>[snip]</span>
<span id="cb55-18"><a href="#cb55-18" tabindex="-1"></a>… with <span class="dv">758</span> more rows</span>
<span id="cb55-19"><a href="#cb55-19" tabindex="-1"></a></span>
<span id="cb55-20"><a href="#cb55-20" tabindex="-1"></a><span class="fu">attr</span>(,<span class="st">"class"</span>)</span>
<span id="cb55-21"><a href="#cb55-21" tabindex="-1"></a>[<span class="dv">1</span>] <span class="st">"list"</span>       <span class="st">"network"</span>    <span class="st">"actor"</span>      <span class="st">"reddit"</span>     <span class="st">"voson_text"</span></span></code></pre></div>
<p>Note that in the above, <code><a href="../reference/AddText.html">AddText()</a></code> was used to add the
comment text data to the network dataframe, stored as an edge attribute.
This list is then passed to <code><a href="../reference/Graph.html">Graph()</a></code>, which returns an
<code>igraph</code> graph object.</p>
<div class="sourceCode" id="cb56"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb56-1"><a href="#cb56-1" tabindex="-1"></a><span class="sc">&gt;</span> actorGraph</span>
<span id="cb56-2"><a href="#cb56-2" tabindex="-1"></a>IGRAPH <span class="dv">5</span>a5d5b9 DN<span class="sc">--</span> <span class="dv">439</span> <span class="dv">768</span> <span class="sc">--</span></span>
<span id="cb56-3"><a href="#cb56-3" tabindex="-1"></a><span class="sc">+</span> attr<span class="sc">:</span> <span class="fu">type</span> (g<span class="sc">/</span>c), <span class="fu">name</span> (v<span class="sc">/</span>c), <span class="fu">user</span> (v<span class="sc">/</span>c), <span class="fu">label</span> (v<span class="sc">/</span>c), subreddit</span>
<span id="cb56-4"><a href="#cb56-4" tabindex="-1"></a><span class="sc">|</span> (e<span class="sc">/</span>c), <span class="fu">thread_id</span> (e<span class="sc">/</span>c), <span class="fu">comment_id</span> (e<span class="sc">/</span>n), <span class="fu">comm_id</span> (e<span class="sc">/</span>c),</span>
<span id="cb56-5"><a href="#cb56-5" tabindex="-1"></a><span class="sc">|</span> <span class="fu">vosonTxt_comment</span> (e<span class="sc">/</span>c), <span class="fu">title</span> (e<span class="sc">/</span>c)</span>
<span id="cb56-6"><a href="#cb56-6" tabindex="-1"></a><span class="sc">+</span> edges from <span class="dv">5</span><span class="fu">a5d5b9</span> (vertex names)<span class="sc">:</span></span>
<span id="cb56-7"><a href="#cb56-7" tabindex="-1"></a> [<span class="dv">1</span>] <span class="dv">1</span> <span class="ot">-&gt;</span><span class="dv">439</span> <span class="dv">2</span> <span class="ot">-&gt;</span><span class="dv">73</span>  <span class="dv">3</span> <span class="ot">-&gt;</span><span class="dv">113</span> <span class="dv">4</span> <span class="ot">-&gt;</span><span class="dv">120</span> <span class="dv">5</span> <span class="ot">-&gt;</span><span class="dv">120</span> <span class="dv">6</span> <span class="ot">-&gt;</span><span class="dv">17</span>  <span class="dv">7</span> <span class="ot">-&gt;</span><span class="dv">194</span> <span class="dv">8</span> <span class="ot">-&gt;</span><span class="dv">20</span>  <span class="dv">9</span> <span class="ot">-&gt;</span><span class="dv">20</span></span>
<span id="cb56-8"><a href="#cb56-8" tabindex="-1"></a>[<span class="dv">10</span>] <span class="dv">10</span><span class="ot">-&gt;</span><span class="dv">165</span> <span class="dv">11</span><span class="ot">-&gt;</span><span class="dv">165</span> <span class="dv">12</span><span class="ot">-&gt;</span><span class="dv">1</span>   <span class="dv">13</span><span class="ot">-&gt;</span><span class="dv">2</span>   <span class="dv">14</span><span class="ot">-&gt;</span><span class="dv">3</span>   <span class="dv">15</span><span class="ot">-&gt;</span><span class="dv">4</span>   <span class="dv">16</span><span class="ot">-&gt;</span><span class="dv">5</span>   <span class="dv">17</span><span class="ot">-&gt;</span><span class="dv">6</span>   <span class="dv">18</span><span class="ot">-&gt;</span><span class="dv">7</span></span>
<span id="cb56-9"><a href="#cb56-9" tabindex="-1"></a>[<span class="dv">19</span>] <span class="dv">19</span><span class="ot">-&gt;</span><span class="dv">8</span>   <span class="dv">20</span><span class="ot">-&gt;</span><span class="dv">9</span>   <span class="dv">21</span><span class="ot">-&gt;</span><span class="dv">10</span>  <span class="dv">22</span><span class="ot">-&gt;</span><span class="dv">11</span>  <span class="dv">23</span><span class="ot">-&gt;</span><span class="dv">12</span>  <span class="dv">2</span> <span class="ot">-&gt;</span><span class="dv">13</span>  <span class="dv">24</span><span class="ot">-&gt;</span><span class="dv">3</span>   <span class="dv">7</span> <span class="ot">-&gt;</span><span class="dv">18</span>  <span class="dv">25</span><span class="ot">-&gt;</span><span class="dv">23</span></span>
<span id="cb56-10"><a href="#cb56-10" tabindex="-1"></a>[<span class="dv">28</span>] <span class="dv">26</span><span class="ot">-&gt;</span><span class="dv">2</span>   <span class="dv">3</span> <span class="ot">-&gt;</span><span class="dv">24</span>  <span class="dv">27</span><span class="ot">-&gt;</span><span class="dv">18</span>  <span class="dv">28</span><span class="ot">-&gt;</span><span class="dv">1</span>   <span class="dv">29</span><span class="ot">-&gt;</span><span class="dv">2</span>   <span class="dv">18</span><span class="ot">-&gt;</span><span class="dv">27</span>  <span class="dv">1</span> <span class="ot">-&gt;</span><span class="dv">28</span>  <span class="dv">30</span><span class="ot">-&gt;</span><span class="dv">2</span>   <span class="dv">31</span><span class="ot">-&gt;</span><span class="dv">7</span></span>
<span id="cb56-11"><a href="#cb56-11" tabindex="-1"></a>[<span class="dv">37</span>] <span class="dv">25</span><span class="ot">-&gt;</span><span class="dv">1</span>   <span class="dv">32</span><span class="ot">-&gt;</span><span class="dv">2</span>   <span class="dv">33</span><span class="ot">-&gt;</span><span class="dv">31</span>  <span class="dv">34</span><span class="ot">-&gt;</span><span class="dv">1</span>   <span class="dv">2</span> <span class="ot">-&gt;</span><span class="dv">32</span>  <span class="dv">35</span><span class="ot">-&gt;</span><span class="dv">7</span>   <span class="dv">25</span><span class="ot">-&gt;</span><span class="dv">34</span>  <span class="dv">36</span><span class="ot">-&gt;</span><span class="dv">2</span>   <span class="dv">7</span> <span class="ot">-&gt;</span><span class="dv">35</span></span>
<span id="cb56-12"><a href="#cb56-12" tabindex="-1"></a>[<span class="dv">46</span>] <span class="dv">37</span><span class="ot">-&gt;</span><span class="dv">1</span>   <span class="dv">38</span><span class="ot">-&gt;</span><span class="dv">2</span>   <span class="dv">39</span><span class="ot">-&gt;</span><span class="dv">7</span>   <span class="dv">40</span><span class="ot">-&gt;</span><span class="dv">1</span>   <span class="dv">41</span><span class="ot">-&gt;</span><span class="dv">2</span>   <span class="dv">42</span><span class="ot">-&gt;</span><span class="dv">7</span>   <span class="dv">43</span><span class="ot">-&gt;</span><span class="dv">1</span>   <span class="dv">2</span> <span class="ot">-&gt;</span><span class="dv">41</span>  <span class="dv">44</span><span class="ot">-&gt;</span><span class="dv">7</span></span>
<span id="cb56-13"><a href="#cb56-13" tabindex="-1"></a><span class="sc">+</span> ... omitted several edges</span></code></pre></div>
<p>The Reddit actor network contains a graph attribute <code>type</code>
(set to “reddit”). The node attributes are: <code>name</code>
(sequential ID number for actor, generated by <code>vosonSML</code>),
<code>user</code> (Reddit handle or screen name)) and <code>label</code>
(a concatenation of the ID and screen name). The edge attributes are:
<code>subreddit</code> (the subreddit from which the post is collected),
<code>thread_id</code> (the 6 character ID of the thread or post),
<code>comment_id</code> (sequential ID number for comment, generated by
<code>vosonSML</code>). There is also an edge attribute
<code>title</code>, which is set to <code>NA</code> for all comments
except the comment representing the original post. Further note that the
original post is represented as a self-loop edge from the user who
authored the post (and this is how the post text can be accessed, as an
edge attribute), however with the Reddit actor network, there is no
<code>edge_type</code> attribute. Finally, because we used
<code><a href="../reference/AddText.html">AddText()</a></code> in the above example, there is also an edge
attribute <code>vosonTxt_comment</code> which is the text associated
with the comment, or original post.</p>
<p>The example Reddit actor network contains 439 nodes and 768 edges.
The following is a visualization of the actor network, where the author
of the post is indicated by a red node, and blue nodes indicate those
people who mentioned “arson” or “starting fires” in at least one of
their comments.</p>
<div class="sourceCode" id="cb57"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># set node color of original post to red based on presence of title edge</span></span>
<span><span class="co"># attribute set other node colors to grey</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">actorGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span> <span class="op">&lt;-</span> <span class="st">"grey"</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">actorGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span><span class="op">[</span><span class="fu"><a href="https://r.igraph.org/reference/tail_of.html" class="external-link">tail_of</a></span><span class="op">(</span></span>
<span>  <span class="va">actorGraph</span>, <span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="op">!</span><span class="fu"><a href="https://rdrr.io/r/base/NA.html" class="external-link">is.na</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/E.html" class="external-link">E</a></span><span class="op">(</span><span class="va">actorGraph</span><span class="op">)</span><span class="op">$</span><span class="va">title</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="op">)</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"red"</span></span>
<span></span>
<span><span class="co"># get node indexes for the tails of edges that have comments containing</span></span>
<span><span class="co"># words of interest set their node colors to blue</span></span>
<span><span class="va">ind</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/tail_of.html" class="external-link">tail_of</a></span><span class="op">(</span></span>
<span>  <span class="va">actorGraph</span>,</span>
<span>  <span class="fu"><a href="https://rdrr.io/r/base/grep.html" class="external-link">grep</a></span><span class="op">(</span><span class="st">"arson|starting fires"</span>,</span>
<span>       <span class="fu"><a href="https://rdrr.io/r/base/chartr.html" class="external-link">tolower</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/E.html" class="external-link">E</a></span><span class="op">(</span><span class="va">actorGraph</span><span class="op">)</span><span class="op">$</span><span class="va">vosonTxt_comment</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="op">)</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">actorGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span><span class="op">[</span><span class="va">ind</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"blue"</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"reddit_actor.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">actorGraph</span>, vertex.label <span class="op">=</span> <span class="st">""</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>, edge.arrow.size <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/reddit_actor.png" alt="Reddit actor network (red node is author of post, blue nodes are users who mentioned arson)"><div class="figcaption">Reddit actor network (red node is author of
post, blue nodes are users who mentioned arson)</div>
</div>
</div>
<div class="section level4">
<h4 id="activity-network-2">Activity Network<a class="anchor" aria-label="anchor" href="#activity-network-2"></a>
</h4>
<p>In the Reddit <em>activity network</em>, nodes are either comments
and/or initial thread posts and the edges represent replies to the
original post, or replies to comments.</p>
<div class="sourceCode" id="cb58"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">activityNetwork</span> <span class="op">&lt;-</span> <span class="va">redditData</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"activity"</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/AddText.html">AddText</a></span><span class="op">(</span><span class="va">redditData</span><span class="op">)</span></span>
<span><span class="va">activityGraph</span> <span class="op">&lt;-</span> <span class="va">activityNetwork</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span>writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
<p><code>Create("activity")</code> returns a named list containing two
dataframes named “nodes” and “edges” (the following has been modified to
preserve anonymity):</p>
<div class="sourceCode" id="cb59"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb59-1"><a href="#cb59-1" tabindex="-1"></a><span class="sc">&gt;</span> activityNetwork</span>
<span id="cb59-2"><a href="#cb59-2" tabindex="-1"></a><span class="sc">$</span>nodes</span>
<span id="cb59-3"><a href="#cb59-3" tabindex="-1"></a><span class="co"># A tibble: 768 x 10</span></span>
<span id="cb59-4"><a href="#cb59-4" tabindex="-1"></a>   id    thread_id comm_id datetime     ts subreddit user  node_type</span>
<span id="cb59-5"><a href="#cb59-5" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>chr<span class="sc">&gt;</span>   <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>dbl<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span>     <span class="er">&lt;</span>chr<span class="sc">&gt;</span> <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb59-6"><a href="#cb59-6" tabindex="-1"></a> <span class="dv">1</span> elcb… elcb9b    xxxxxxx <span class="dv">2020-01</span>… <span class="fl">1.58e9</span> worldnews xxxx… comment</span>
<span id="cb59-7"><a href="#cb59-7" tabindex="-1"></a> <span class="dv">2</span> elcb… elcb9b    xxxxxxx <span class="dv">2020-01</span>… <span class="fl">1.58e9</span> worldnews xxxx… comment</span>
<span id="cb59-8"><a href="#cb59-8" tabindex="-1"></a>[snip]</span>
<span id="cb59-9"><a href="#cb59-9" tabindex="-1"></a><span class="co"># … with 758 more rows, and 2 more variables: vosonTxt_comment &lt;chr&gt;,</span></span>
<span id="cb59-10"><a href="#cb59-10" tabindex="-1"></a><span class="co">#   title &lt;chr&gt;</span></span>
<span id="cb59-11"><a href="#cb59-11" tabindex="-1"></a></span>
<span id="cb59-12"><a href="#cb59-12" tabindex="-1"></a><span class="sc">$</span>edges</span>
<span id="cb59-13"><a href="#cb59-13" tabindex="-1"></a><span class="co"># A tibble: 767 x 3</span></span>
<span id="cb59-14"><a href="#cb59-14" tabindex="-1"></a>   from                       to                       edge_type</span>
<span id="cb59-15"><a href="#cb59-15" tabindex="-1"></a>   <span class="sc">&lt;</span>chr<span class="sc">&gt;</span>                      <span class="er">&lt;</span>chr<span class="sc">&gt;</span>                    <span class="er">&lt;</span>chr<span class="sc">&gt;</span></span>
<span id="cb59-16"><a href="#cb59-16" tabindex="-1"></a> <span class="dv">1</span> elcb9b<span class="fl">.1</span>                   elcb9b<span class="fl">.0</span>                 comment</span>
<span id="cb59-17"><a href="#cb59-17" tabindex="-1"></a> <span class="dv">2</span> elcb9b<span class="fl">.4</span>_1_1_1_1_1_1_1_1_1 elcb9b<span class="fl">.4</span>_1_1_1_1_1_1_1_1 comment</span>
<span id="cb59-18"><a href="#cb59-18" tabindex="-1"></a>[snip]</span>
<span id="cb59-19"><a href="#cb59-19" tabindex="-1"></a><span class="co"># … with 757 more rows</span></span>
<span id="cb59-20"><a href="#cb59-20" tabindex="-1"></a></span>
<span id="cb59-21"><a href="#cb59-21" tabindex="-1"></a><span class="fu">attr</span>(,<span class="st">"class"</span>)</span>
<span id="cb59-22"><a href="#cb59-22" tabindex="-1"></a>[<span class="dv">1</span>] <span class="st">"list"</span>       <span class="st">"network"</span>    <span class="st">"activity"</span>   <span class="st">"reddit"</span>     <span class="st">"voson_text"</span></span></code></pre></div>
<p>Note that in the above, <code><a href="../reference/AddText.html">AddText()</a></code> was used to add the
comment text data to the network dataframe, stored as a node attribute.
This list is then passed to <code><a href="../reference/Graph.html">Graph()</a></code>, which returns an
<code>igraph</code> graph object.</p>
<div class="sourceCode" id="cb60"><pre class="sourceCode r"><code class="sourceCode r"><span id="cb60-1"><a href="#cb60-1" tabindex="-1"></a><span class="sc">&gt;</span> activityGraph</span>
<span id="cb60-2"><a href="#cb60-2" tabindex="-1"></a>IGRAPH <span class="fl">09e30</span>ea DN<span class="sc">--</span> <span class="dv">768</span> <span class="dv">767</span> <span class="sc">--</span></span>
<span id="cb60-3"><a href="#cb60-3" tabindex="-1"></a><span class="sc">+</span> attr<span class="sc">:</span> <span class="fu">type</span> (g<span class="sc">/</span>c), <span class="fu">name</span> (v<span class="sc">/</span>c), <span class="fu">thread_id</span> (v<span class="sc">/</span>c), <span class="fu">comm_id</span> (v<span class="sc">/</span>c),</span>
<span id="cb60-4"><a href="#cb60-4" tabindex="-1"></a><span class="sc">|</span> <span class="fu">datetime</span> (v<span class="sc">/</span>c), <span class="fu">ts</span> (v<span class="sc">/</span>n), <span class="fu">subreddit</span> (v<span class="sc">/</span>c), <span class="fu">user</span> (v<span class="sc">/</span>c), node_type</span>
<span id="cb60-5"><a href="#cb60-5" tabindex="-1"></a><span class="sc">|</span> (v<span class="sc">/</span>c), <span class="fu">vosonTxt_comment</span> (v<span class="sc">/</span>c), <span class="fu">title</span> (v<span class="sc">/</span>c), <span class="fu">label</span> (v<span class="sc">/</span>c), edge_type</span>
<span id="cb60-6"><a href="#cb60-6" tabindex="-1"></a><span class="sc">|</span> (e<span class="sc">/</span>c)</span>
<span id="cb60-7"><a href="#cb60-7" tabindex="-1"></a><span class="sc">+</span> edges from <span class="fl">09e30</span><span class="fu">ea</span> (vertex names)<span class="sc">:</span></span>
<span id="cb60-8"><a href="#cb60-8" tabindex="-1"></a>[<span class="dv">1</span>] elcb9b<span class="fl">.1</span>                  <span class="ot">-&gt;</span>elcb9b<span class="fl">.0</span></span>
<span id="cb60-9"><a href="#cb60-9" tabindex="-1"></a>[<span class="dv">2</span>] elcb9b<span class="fl">.4</span>_1_1_1_1_1_1_1_1_1<span class="ot">-&gt;</span>elcb9b<span class="fl">.4</span>_1_1_1_1_1_1_1_1</span>
<span id="cb60-10"><a href="#cb60-10" tabindex="-1"></a>[<span class="dv">3</span>] elcb9b<span class="fl">.4</span>_1_1_4_2_1_1_1_1_1<span class="ot">-&gt;</span>elcb9b<span class="fl">.4</span>_1_1_4_2_1_1_1_1</span>
<span id="cb60-11"><a href="#cb60-11" tabindex="-1"></a>[<span class="dv">4</span>] elcb9b<span class="fl">.4</span>_1_1_4_3_1_1_1_3_1<span class="ot">-&gt;</span>elcb9b<span class="fl">.4</span>_1_1_4_3_1_1_1_3</span>
<span id="cb60-12"><a href="#cb60-12" tabindex="-1"></a>[<span class="dv">5</span>] elcb9b<span class="fl">.4</span>_1_1_4_3_1_1_1_3_2<span class="ot">-&gt;</span>elcb9b<span class="fl">.4</span>_1_1_4_3_1_1_1_3</span>
<span id="cb60-13"><a href="#cb60-13" tabindex="-1"></a><span class="sc">+</span> ... omitted several edges</span></code></pre></div>
<p>The Reddit activity network contains a graph attribute
<code>type</code> (set to “reddit”). The node attributes are:
<code>name</code> (string showing position of the comment in the
thread), <code>date</code> (date when the comment was authored, in
DD-MM-YY format), <code>subreddit</code> (the subreddit from which the
post is collected), <code>user</code> (Reddit handle or screen name of
the user who authored the comment or post), <code>node_type</code>
(‘comment’ or ‘thread’), <code>title</code> (<code>NA</code> for all
nodes except that representing the original post), <code>label</code> (a
concatenation of <code>name</code> and <code>user</code>). Because we
used <code><a href="../reference/AddText.html">AddText()</a></code> in the above example, there is also a node
attribute <code>vosonTxt_comment</code> which is the text from the
comment, or original post. The edge attributes is <code>edge_type</code>
which is ‘comment’ for all edges.</p>
<p>The example Reddit activity network contains 768 nodes and 767 edges.
The following is a visualisation of the network, where the post is
indicated by a red node, and blue indicates those comments that include
the words “arson” or “starting fires”.</p>
<div class="sourceCode" id="cb61"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># set original post node colors to red based on a node type of thread</span></span>
<span><span class="co"># set other node colors to grey</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span> <span class="op">&lt;-</span> <span class="st">"grey"</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span><span class="op">[</span><span class="fu"><a href="https://rdrr.io/r/base/which.html" class="external-link">which</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">node_type</span> <span class="op">==</span> <span class="st">"thread"</span><span class="op">)</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"red"</span></span>
<span></span>
<span><span class="co"># get node indexes for nodes that have comment attributes containing words of interest</span></span>
<span><span class="co"># set their node colors to blue</span></span>
<span><span class="va">ind</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://rdrr.io/r/base/grep.html" class="external-link">grep</a></span><span class="op">(</span><span class="st">"arson|starting fires"</span>, <span class="fu"><a href="https://rdrr.io/r/base/chartr.html" class="external-link">tolower</a></span><span class="op">(</span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">vosonTxt_comment</span><span class="op">)</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">activityGraph</span><span class="op">)</span><span class="op">$</span><span class="va">color</span><span class="op">[</span><span class="va">ind</span><span class="op">]</span> <span class="op">&lt;-</span> <span class="st">"blue"</span></span>
<span></span>
<span><span class="co"># open and write plot to a png file</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/png.html" class="external-link">png</a></span><span class="op">(</span><span class="st">"reddit_activity.png"</span>, width <span class="op">=</span> <span class="fl">600</span>, height <span class="op">=</span> <span class="fl">600</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/graphics/plot.default.html" class="external-link">plot</a></span><span class="op">(</span><span class="va">activityGraph</span>, vertex.label <span class="op">=</span> <span class="st">""</span>, vertex.size <span class="op">=</span> <span class="fl">4</span>, edge.arrow.size <span class="op">=</span> <span class="fl">0.5</span><span class="op">)</span></span>
<span><span class="fu"><a href="https://rdrr.io/r/grDevices/dev.html" class="external-link">dev.off</a></span><span class="op">(</span><span class="op">)</span></span></code></pre></div>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/reddit_activity.png" alt="Reddit activity network (red node is intial post, blue nodes are comments mentioning arson)"><div class="figcaption">Reddit activity network (red node is intial
post, blue nodes are comments mentioning arson)</div>
</div>
</div>
</div>
</div>
<div class="section level2">
<h2 id="merging-collected-data">Merging Collected Data<a class="anchor" aria-label="anchor" href="#merging-collected-data"></a>
</h2>
<p>Data that was collected at different times, used different collect
parameters or was saved to multiple files can be merged by using
functions that operate on dataframes. The data from <code>Collect</code>
is output in <code>tibble</code> (dataframe) format and provided each
collected data set are from the same social media type can be combined
using the <code>rbind</code> function.</p>
<p>In the examples below or cases that involve large datasets, it can
sometimes be more efficient or timely to substitute optimized functions
such as <code><a href="https://dplyr.tidyverse.org/reference/bind_rows.html" class="external-link">dplyr::bind_rows</a></code> for <code>rbind</code> or
<code><a href="https://rdatatable.gitlab.io/data.table/reference/rbindlist.html" class="external-link">data.table::rbindlist</a></code> instead of
<code>do.call("rbind", list)</code>.</p>
<div class="section level3">
<h3 id="merging-from-multiple-collect-operations">Merging from multiple Collect operations<a class="anchor" aria-label="anchor" href="#merging-from-multiple-collect-operations"></a>
</h3>
<p>Data collected in the same session can be merged using the
<code>Merge</code> function. The following twitter example combines
tweet data collected using different search parameters. The result is
combined most <code>recent</code> tweets using the <code>#auspol</code>
hashtag and most <code>popular</code> tweets using the
<code>#bushfire</code> hashtag.</p>
<div class="sourceCode" id="cb62"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># collect twitter data for the #auspol hashtag</span></span>
<span><span class="va">auspolTwitterData</span> <span class="op">&lt;-</span> <span class="va">twitterAuth</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu"><a href="../reference/Collect.html">Collect</a></span><span class="op">(</span>searchTerm <span class="op">=</span> <span class="st">"#auspol"</span>, searchType <span class="op">=</span> <span class="st">"recent"</span>, numTweets <span class="op">=</span> <span class="fl">100</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># collect twitter data for the #bushfire hashtag</span></span>
<span><span class="va">bushfireTwitterData</span> <span class="op">&lt;-</span> <span class="va">twitterAuth</span> <span class="op">|&gt;</span></span>
<span>  <span class="fu"><a href="../reference/Collect.html">Collect</a></span><span class="op">(</span>searchTerm <span class="op">=</span> <span class="st">"#bushfire"</span>, searchType <span class="op">=</span> <span class="st">"popular"</span>, numTweets <span class="op">=</span> <span class="fl">50</span><span class="op">)</span></span>
<span></span>
<span><span class="co"># combine the collected data for the different hashtags</span></span>
<span><span class="va">twitterData</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/Merge.html">Merge</a></span><span class="op">(</span><span class="va">auspolTwitterData</span>, <span class="va">bushfireTwitterData</span>, writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level3">
<h3 id="merging-files-in-a-directory">Merging files in a directory<a class="anchor" aria-label="anchor" href="#merging-files-in-a-directory"></a>
</h3>
<p>If there are many data collections to be merged from file
<code>vosonSML</code> has a <code>MergeFiles</code> function. In this
example a list of twitter collection files in the
<code>2019TwitterBushfireData</code> directory that end in
“TwitterData.rds” are merged together.</p>
<div class="sourceCode" id="cb63"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="va">twitterData</span> <span class="op">&lt;-</span> <span class="fu"><a href="../reference/MergeFiles.html">MergeFiles</a></span><span class="op">(</span></span>
<span>  <span class="st">"2019TwitterBushfireData"</span>, pattern <span class="op">=</span> <span class="st">"*TwitterData.rds"</span></span>
<span><span class="op">)</span></span></code></pre></div>
</div>
<div class="section level3">
<h3 id="creating-a-network-and-graph-from-merged-data">Creating a network and graph from merged data<a class="anchor" aria-label="anchor" href="#creating-a-network-and-graph-from-merged-data"></a>
</h3>
<p>Once the data is merged then it can then simply be passed to the
<code>Create</code> function to create a network as per the usual
<code>vosonSML</code> work flow.</p>
<div class="sourceCode" id="cb64"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="co"># create an igraph of twitter actor network</span></span>
<span><span class="va">actorGraph</span> <span class="op">&lt;-</span> <span class="va">twitterData</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Create.html">Create</a></span><span class="op">(</span><span class="st">"actor"</span><span class="op">)</span> <span class="op">|&gt;</span> <span class="fu"><a href="../reference/Graph.html">Graph</a></span><span class="op">(</span>writeToFile <span class="op">=</span> <span class="cn">TRUE</span><span class="op">)</span></span></code></pre></div>
</div>
</div>
<div class="section level2">
<h2 id="voson-dashboard">VOSON Dashboard<a class="anchor" aria-label="anchor" href="#voson-dashboard"></a>
</h2>
<p>It is possible to import a network created using
<code>vosonSML</code>, and saved as a “.graphml” file, into
<code>VOSON Dashboard</code>. However, if you have created a categorical
node attribute in the network and wish to plot networks in
<code>VOSON Dashboard</code> with node colour reflecting the node
attribute, then the node attribute name has to be pre-pended with
“vosonCA_”. This let’s <code>VOSON Dashboard</code> know the attribute
is to be treated as categorical.</p>
<p>Above, we created a Twitter subnetwork: the giant component in the
reply network, with red nodes indicating those users who tweeted using
the word “bushfire”. We did this by created a node attribute
“tweetedBushfires”. For <code>VOSON Dashboard</code> to recognise this
node attribute, it has to be named “vosonCA_tweetedBushfires”. The
following code creates a new node attribute with this name, and sames
the network as a graphml file:</p>
<div class="sourceCode" id="cb65"><pre class="downlit sourceCode r">
<code class="sourceCode R"><span><span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g3</span><span class="op">)</span><span class="op">$</span><span class="va">vosonCA_tweetedBushfires</span> <span class="op">&lt;-</span> <span class="fu"><a href="https://r.igraph.org/reference/V.html" class="external-link">V</a></span><span class="op">(</span><span class="va">g3</span><span class="op">)</span><span class="op">$</span><span class="va">tweetedBushfires</span></span>
<span><span class="fu"><a href="https://r.igraph.org/reference/write.graph.html" class="external-link">write.graph</a></span><span class="op">(</span><span class="va">g3</span>, <span class="st">"g3.graphml"</span>, format <span class="op">=</span> <span class="st">"graphml"</span><span class="op">)</span></span></code></pre></div>
<p>The following shows a screenshot of <code>VOSON Dashboard</code> with
this network loaded and the “tweetedBushfires” attribute has been
seleced to be reflected in the node colour.</p>
<div class="float">
<img src="https://vosonlab.github.io/vosonSML/images/intro-to-vosonsml/voson_dashboard.png" alt="VOSON Dashboard with Twitter network of users who tweeted using the word “bushfire”"><div class="figcaption">VOSON Dashboard with Twitter network of users
who tweeted using the word “bushfire”</div>
</div>
</div>
<div class="section level2">
<h2 id="acknowledgements">Acknowledgements<a class="anchor" aria-label="anchor" href="#acknowledgements"></a>
</h2>
<p><code>vosonSML</code> and <code>VOSON Dashboard</code> are developed
and maintained at the <a href="http://vosonlab.net/" class="external-link">Virtual Observatory
for the Study of Online Networks (VOSON) Lab</a> at the Australian
National University.</p>
<p><code>vosonSML</code> was originally released on CRAN in November
2015 as the package <code>SocialMediaLab</code> (Timothy Graham was the
lead developer), with the significantly revised and renamed
<code>vosonSML</code> being released on CRAN in July 2018 (Bryan Gertzel
is the lead developer).</p>
<p>We acknowledge the contributions of Chung-hong Chan who implemented a
revised UI (involving <code>magrittr</code> pipes) in the original
<code>SocialMediaLab</code> package and Xiaolan Cai who has contributed
to documentation.</p>
</div>
  </main><aside class="col-md-3"><nav id="toc" aria-label="Table of contents"><h2>On this page</h2>
    </nav></aside>
</div>



    <footer><div class="pkgdown-footer-left">
  <p>Developed by <a href="https://vosonlab.net" class="external-link"><span>VOSON Lab</span></a>.</p>
</div>

<div class="pkgdown-footer-right">
  <p>Site built with <a href="https://pkgdown.r-lib.org/" class="external-link">pkgdown</a> 2.1.0.</p>
</div>

    </footer>
</div>





  </body>
</html>
