## Loading required package: NLP
##
## Attaching package: 'ggplot2'
## The following object is masked from 'package:NLP':
##
## annotate
## Loading required package: RColorBrewer
## [1] "Using direct authentication"
## [1] "user"
## attr(,"package")
## [1] "twitteR"
## Reference Class "status":
##
## Class fields:
##
## Name: text favorited favoriteCount replyToSN created
## Class: character logical numeric character POSIXct
##
## Name: truncated replyToSID id replyToUID statusSource
## Class: logical character character character character
##
## Name: screenName retweetCount isRetweet retweeted longitude
## Class: character numeric logical logical character
##
## Name: latitude urls
## Class: character data.frame
##
## Class Methods:
## "setUrls", "getRetweets", "getRefClass", "getUrls", "setTruncated",
## "setText", "getReplyToSID", "getText", "export", "setCreated",
## "setFavoriteCount", "getCreated", "initialize", "callSuper",
## "getRetweeters", "initFields", "getClass", "setReplyToUID", "import",
## "setLatitude", "setIsRetweet", "getFavoriteCount", "getRetweetCount",
## "getIsRetweet", "setId", "setScreenName", "getLatitude", "getScreenName",
## "toDataFrame#twitterObj", "setRetweetCount", "setReplyToSID", "getId",
## "getReplyToUID", "setFavorited", "getRetweeted", "getFavorited",
## "toDataFrame", "setStatusSource", "setReplyToSN", "copy", "usingMethods",
## "setRetweeted", "field", ".objectParent", "getTruncated", "untrace",
## "trace", "setLongitude", "getLongitude", "getStatusSource",
## ".objectPackage", "getReplyToSN", "show"
##
## Reference Superclasses:
## "twitterObj", "envRefClass"
library(tidytext)
# optional
# library(httr)# Set proxy options
#set_config( use_proxy( url = "http://proxy-chain.intel.com", port = 911));
# set_config( use_proxy( url = "http://189.50.4.170", port = 8080));
#trendingTweets.df$text <- sapply(tweets.df$text,function(x) iconv(x,to='UTF-8'))
#commented out due to missing text
trendingTweets.df = twListToDF(trendingTweets)
class(trendingTweets.df)
trendingTweets.df$text <- sapply(trendingTweets.df$text,function(x) iconv(x,to='UTF-8'))
trendingTweets.df$text <- sapply(trendingTweets.df$text,function(x) iconv(enc2utf8(x), sub="byte"))
library(syuzhet)
library(tidytext)
tweetSentiments <- get_sentiment (trendingTweets.df$text,method = "syuzhet")
tweets <- cbind(trendingTweets.df, tweetSentiments)
## [[1]]
## [1] "weareoneEXO: [<U+C2E0><U+ACFC> <U+D568><U+AED8> 6<U+D68C> <U+C120><U+ACF5><U+AC1C>] 5MC <U+B9DE><U+CDA4><U+D615> <U+D37C><U+C2A4><U+B110> <U+CE75><U+D14C><U+C77C><U+C740>?<U+0001F379>\n\n<U+0001F449> https://t.co/5U6kFN00zO\n\n5<U+C6D4> 14<U+C77C>(<U+AE08>) <U+C624><U+D6C4> 10<U+C2DC> 20<U+BD84> <U+BC29><U+C1A1>!<U+2744><U+FE0F><U+0001F4FA>\n\n#<U+C2DC><U+C6B0><U+BBFC> #XIUMIN\n#<U+C5D1><U+C18C> #EXO #weareoneEXO\n#<U+C2E0><U+ACFC><U+D568><U+AED8> #<U+CC44><U+B110>S"

ggplot(tweets, aes(sentiment, fill = sentiment)) +
geom_bar() +
theme(legend.position="none", axis.title.x = element_blank()) +
ylab("Number of tweets") +
ggtitle("Tweets by Sentiment")
# NRC Sample (various emotions such as anger, fear, joy, ...)
tweetSentiments <- get_nrc_sentiment(trendingTweets.df$text)
head(tweetSentiments)
#viewing of the tweets
trendingTweets.df$text[5]
tweets <- cbind(trendingTweets.df, tweetSentiments)
tweets[c(1:5),c(1, 17:26)]
sentimentTotals <- data.frame(colSums(tweets[,c(17:26)]))
names(sentimentTotals) <- "count"
sentimentTotals <- cbind("sentiment" = rownames(sentimentTotals), sentimentTotals)
rownames(sentimentTotals) <- NULL
sentimentTotals
ggplot(data = sentimentTotals, aes(x = sentiment, y = count)) +
geom_bar(aes(fill = sentiment), stat = "identity") +
theme(legend.position = "none") +
xlab("Sentiment") + ylab("Total Count") + ggtitle("Total Sentiment Score for All Tweets")