<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/sentiment-analysis-of-trumps-tweets-with-r/"></div></div><div><a data-url="https://www.r-bloggers.com/sentiment-analysis-of-trumps-tweets-with-r/" data-counturl="https://www.r-bloggers.com/sentiment-analysis-of-trumps-tweets-with-r/" data-count="horizontal" data-text="Sentiment analysis of Trump’s tweets with R" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="http://blog.revolutionanalytics.com/2016/08/sentiment-analysis-of-trumps-tweets-with-r.html"> Revolutions</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<div>
<p>Data Scientist David Robinson caused a bit of a stir in the media <a target="_blank" href="http://varianceexplained.org/r/trump-tweets/">when he analyzed Donald Trump's tweets</a> and revealed that <a target="_blank" href="https://twitter.com/RealRealDonaldT">those sent from an Android device</a> were likely sent by the candidate himself, while those sent from an iPhone were likely sent by campaign staffers. The difference? As seen in the chart below, Android-based tweets used angrier, negative words while iPhone-based tweets tended be straightforward campaign announcements and hashtag promotions. The news was reported in <a target="_blank" href="http://www.scientificamerican.com/article/only-some-of-realdonaldtrump-s-tweets-are-actually-donald-trump/">Scientific American</a>, the <a target="_blank" href="http://www.latimes.com/nation/politics/trailguide/la-na-trailguide-updates-trump-tweets-iphone-android-1470868218-htmlstory.html">LA Times</a>, <a target="_blank" href="http://www.pcmag.com/news/346968/does-trump-really-write-all-of-his-tweets">PC Magazine</a> and David even gave an <a target="_blank" href="http://time.com/4448447/donald-trump-tweets-data-analysis/">interview with Time magazine</a>. </p>
<p><a target="_blank" href="http://varianceexplained.org/r/trump-tweets/"><img title="Trump" alt="Trump" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01bb092bec79970d-800wi" border="0"></a></p>
<p>David used the <a target="_blank" href="https://mran.microsoft.com/documents/what-is-r/">R language</a> and several contributed packages to analyze Trump's tweets. (The R code behind the analysis is <a target="_blank" href="https://github.com/dgrtwo/dgrtwo.github.com/blob/master/_R/2016-08-09-trump-tweets.Rmd">available on Github</a> as an R Markdown document, which also makes an excellent example of literate programming with R.) He used the <a target="_blank" href="https://mran.microsoft.com/package/twitteR/">twitteR package</a> and the <a target="_blank" href="http://www.rdocumentation.org/packages/twitteR/versions/1.1.9/topics/timelines">userTimeline</a> function to download tweets and metadata from the @realDonaldTrump account, which formed the raw data for the analysis. The <a target="_blank" href="https://github.com/juliasilge/tidytext">tidytext package</a> function <a target="_blank" href="http://www.rdocumentation.org/packages/tidytext/versions/0.1.1/topics/unnest_tokens">unnest_tokens</a> extracted and standardized individual words from the tweets, from which simple tabulation generated the chart above of words more frequently used by iPhone and Android tweets. The tidytext package was also used to measure the sentiment of the words used, and again there was a clear difference between iPhone and Android tweets in use of words related to sadness, fear, anger and disgust; and surprise, anticipation, trust and joy.</p>
<p><a target="_blank" href="http://varianceexplained.org/r/trump-tweets/"><img title="Trump sentiments" alt="Trump sentiments" src="http://revolution-computing.typepad.com/.a/6a010534b1db25970b01b8d2124990970c-800wi" border="0"></a></p>
<p>For more details on David's analysis of the Trump tweets, and a fascinating hypothesis that an iPhone-based staffer is attempting to emulate the style of the real Trump's tweets, check out his blog post linked below.</p>
<p>Variance Explained: <a target="_blank" href="http://varianceexplained.org/r/trump-tweets/">Text analysis of Trump's tweets confirms he writes only the (angrier) Android half</a></p>
</div>
<p><div><div><div><div data-width="55" data-show-faces="false" data-send="true" data-layout="box_count" data-height="62" data-href="https://www.r-bloggers.com/sentiment-analysis-of-trumps-tweets-with-r/"></div></div><div><a data-url="https://www.r-bloggers.com/sentiment-analysis-of-trumps-tweets-with-r/" data-counturl="https://www.r-bloggers.com/sentiment-analysis-of-trumps-tweets-with-r/" data-count="vertical" data-text="Sentiment analysis of Trump’s tweets with R" class="twitter-share-button" data-via="rbloggers" href="https://twitter.com/share"></a></div><div></div></div><div></div></div>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="http://blog.revolutionanalytics.com/2016/08/sentiment-analysis-of-trumps-tweets-with-r.html"> Revolutions</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/?s=data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/?s=Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/?s=map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/?s=animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/?s=sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/?s=LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/?s=SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/?s=eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/?s=git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/?s=hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/?s=Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/?s=regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/?s=PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/?s=time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/?s=trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/a7AvfLWui1c"></a></div>