<p><div><div><div><div data-show-faces="false" data-height="21" data-width="100" data-layout="button_count" data-send="true" data-href="https://www.r-bloggers.com/australian-mp-tweets-collection-and-quick-analysis/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://datascienceplus.com/australian-mp-tweets-collection-and-quick-analysis/"> R Programming – DataScience+</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<ul></ul>
<p><strong>
<p>Categories</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/category/visualizing-data/" title="Permanent Link toVisualizing Data" target="_blank">Visualizing Data</a></li>
</ol>
<p><strong>
<p>Tags</p>
<p></p></strong>
<ol>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/rstats/" title="Permanent Link toR Programming" target="_blank">R Programming</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/text-mining/" title="Permanent Link toText Mining" target="_blank">Text Mining</a></li>
<li><a rel="nofollow" href="https://datascienceplus.com/tag/wordcloud/" title="Permanent Link toWordCloud" target="_blank">WordCloud</a></li>
</ol>
<p>Having state election coming soon in Victoria (Australian state where I live) I decided to make a quick analysis and compare what politicians from major Australian party’s post in their Twitter accounts.</p>
<p>I have collected Twitter hanldes of Australian Parliament members (also referred in text and code as MP that states for Member of Parliament) grouped by party. If you are interested how I did it using RSelenium you are welcome to check it in my <a rel="nofollow" href="https://levashov.biz/scrapping-data-about-australian-politicians-with-rselenium/" target="_blank">blog post</a>. </p>
<p>Now I'll use this dataset to collect tweets and do a quick analysis. Start from loading required libraries and the dataframe with Twitter handles.</p>
<pre><code>library(dplyr)
library(purrr)
library(twitteR)
#load dataset from CSV file
mps &lt;- read.csv('mps.csv')
</code></pre>
<p>Filter out MPS without Twitter accounts and smaller parties and separate it to different objects</p>
<pre><code>majors &lt;- c(&quot;Australian Labor Party&quot;, &quot;Liberal Party of Australia&quot;, &quot;The Nationals&quot;)
mp2 &lt;- mps %>% filter(twitter!=&quot;NA&quot; &amp; party %in% majors) %>% group_by(party)
labor &lt;- mp2 %>% filter(party==&quot;Australian Labor Party&quot;)
libs &lt;- mp2 %>% filter(party==&quot;Liberal Party of Australia&quot;)
nationals &lt;- mp2 %>% filter(party==&quot;The Nationals&quot;)
</code></pre>
<p>No lets check number of accounts per party</p>
<pre><code>mp2 %>% summarise(n = n())</code>
<em>## # A tibble: 3 x 2
## party n
## </em></pre>