library('knitr')
library('markdown')
library('tidyr')
library('RCurl')
library('plyr')
library('dplyr')
library('ggplot2')

Test run with one day of tweets only

Import CSV

x <- getURL("https://raw.githubusercontent.com/spsstudent15/Data607FinalProject/master/Tweets%20for%2005.06.2016.csv") #import twitter CSV

tweets506<- data.frame(read.csv(text=x, header=T)) #create data frame

head(tweets506) #show head
##   X
## 1 1
## 2 2
## 3 3
## 4 4
## 5 5
## 6 6
##                                                                                                                                              tweet
## 1 I gotta write something on Tiger.  When I came out of #Baaghi I knew movie would do well&amp;his star power would grow. Why everyone surprised??
## 2                                                                               WATCH BAAGHI 2016 MOVIE ONLINE FOR\xa0FREE https://t.co/6xOPr0jH39
## 3                                       @WahooFX Been checking out Key and Peele after seeing their movie, Keanu. Very clever writing. Funny guys.
## 4                                                     RT @_BWD_: fun movie, that Keanu. glad I got to see and review it: \nhttps://t.co/BwJxnK9YiX
## 5          #LaurenceFishburne Matrix #DVD Movie with Keanu Reeves and Laurence Fishburne by Warn Bros https://t.co/ykY11khlj3 #TheMatrix #Morpheus
## 6  RT @Tribeca: Key and Peele's subversive intelligence powers the comedy duo's gleefully-absurd #KEANU. https://t.co/EKnyjGUklc https://t.co/\x85
##            city  movie        day Sentiment_Score
## 1 New York City Baaghi 05.06.2016       0.5727997
## 2       Seattle Baaghi 05.06.2016       0.2353356
## 3 New York City  Keanu 05.06.2016       0.8883232
## 4 New York City  Keanu 05.06.2016       0.9949679
## 5 New York City  Keanu 05.06.2016       0.5196816
## 6 New York City  Keanu 05.06.2016       0.3208861

Average score by movie

moviesum<- ddply(tweets506, .(movie), summarize,  Sentiment_Score=mean(Sentiment_Score)) #summarize by movie
      
moviesum
##                        movie Sentiment_Score
## 1         A Beautiful Planet       0.9057405
## 2                     Baaghi       0.4040677
## 3                      Dough       0.5768954
## 4                 Green Room       0.6289183
## 5                      Keanu       0.7635731
## 6              Men & Chicken       0.8929113
## 7            Mother\x92s Day       0.7848442
## 8         Older Than Ireland       0.2630552
## 9            Ratchet & Clank       0.6356453
## 10           The Family Fang       0.4418001
## 11 The Man Who Knew Infinity       0.9159938
## 12               The Meddler       0.3039157
## 13                  Viktoria       0.4310602
## 14                      Viva       0.4730699

Average score by movie and city

moviecitysum<- ddply(tweets506, .(movie, city), summarize,  Sentiment_Score=mean(Sentiment_Score)) #summarize by movie and city
      
moviecitysum
##                        movie          city Sentiment_Score
## 1         A Beautiful Planet       Houston      0.98532141
## 2         A Beautiful Planet   Los Angeles      0.82615958
## 3                     Baaghi New York City      0.57279971
## 4                     Baaghi       Seattle      0.23533563
## 5                      Dough   Los Angeles      0.57689536
## 6                 Green Room       Chicago      0.55915763
## 7                 Green Room       Denver       0.65774505
## 8                 Green Room       Houston      0.09630323
## 9                 Green Room   Los Angeles      0.59954875
## 10                Green Room New York City      0.73919461
## 11                     Keanu       Chicago      0.89845158
## 12                     Keanu       Houston      0.60632967
## 13                     Keanu   Los Angeles      0.61189566
## 14                     Keanu New York City      0.82320652
## 15                     Keanu    St. Louis       0.65205039
## 16             Men & Chicken   Los Angeles      0.89291128
## 17           Mother\x92s Day        Boston      0.95848407
## 18           Mother\x92s Day       Chicago      0.62280711
## 19           Mother\x92s Day       Denver       0.80076838
## 20           Mother\x92s Day       Houston      0.88672895
## 21           Mother\x92s Day   Los Angeles      0.78878554
## 22           Mother\x92s Day New York City      0.77102344
## 23        Older Than Ireland        Boston      0.26305515
## 24           Ratchet & Clank       Denver       0.75339541
## 25           Ratchet & Clank      Lincoln       0.07560809
## 26           Ratchet & Clank   Los Angeles      0.49815989
## 27           Ratchet & Clank   New Orleans      0.74542750
## 28           Ratchet & Clank New York City      0.73535306
## 29           Ratchet & Clank       Seattle      0.71106962
## 30           The Family Fang       Chicago      0.44180008
## 31 The Man Who Knew Infinity       Denver       0.91599379
## 32               The Meddler   Los Angeles      0.31883384
## 33               The Meddler New York City      0.21440678
## 34                  Viktoria   Los Angeles      0.43106017
## 35                      Viva       Seattle      0.47306988

Average score by city

citysum<- ddply(tweets506, .(city), summarize,  Sentiment_Score=mean(Sentiment_Score)) #summarize by city
      
citysum
##             city Sentiment_Score
## 1         Boston      0.61076961
## 2        Chicago      0.74875887
## 3        Denver       0.78197566
## 4        Houston      0.66005015
## 5       Lincoln       0.07560809
## 6    Los Angeles      0.65227636
## 7    New Orleans      0.74542750
## 8  New York City      0.77536191
## 9        Seattle      0.56832288
## 10    St. Louis       0.65205039

[Verification Step] Show List of Unique Movies

allmovies<-unique(tweets506[c("movie")]) # get unique movies
allmovies$num<-seq.int(nrow(allmovies)) # add counter row
allmovies #show unique values for movie name
##                         movie num
## 1                      Baaghi   1
## 3                       Keanu   2
## 46                      Dough   3
## 47            The Family Fang   4
## 48  The Man Who Knew Infinity   5
## 49                       Viva   6
## 50            Mother\x92s Day   7
## 88         Older Than Ireland   8
## 89         A Beautiful Planet   9
## 91            Ratchet & Clank  10
## 105                  Viktoria  11
## 106             Men & Chicken  12
## 107               The Meddler  13
## 114                Green Room  14

Graphs by Average Movie Sentiment and Average City Sentiment

ggplot(
  moviesum, aes(x = reorder(movie,Sentiment_Score), y = Sentiment_Score, fill=Sentiment_Score)) + 
  geom_bar(stat="identity") +
  ggtitle("Movie Average Sentiment Score")+ 
  theme(axis.text=element_text(angle=90))+
  labs(x="Movies",y="Score")

ggplot(
  citysum, aes(x = reorder(city,Sentiment_Score), y = Sentiment_Score, fill=Sentiment_Score)) + 
  geom_bar(stat="identity") +
  ggtitle("City Average Sentiment Score")+ 
  theme(axis.text=element_text(angle=90))+
  labs(x="City",y="Score")