Skip to content

Commit

Permalink
pushing everything i had in case missed something
Browse files Browse the repository at this point in the history
  • Loading branch information
sheikhshafayat committed May 28, 2022
1 parent 0ba203d commit 3eb06bf
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 19 deletions.
13 changes: 7 additions & 6 deletions DataAnalysis/Q3/BigramWordCloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ foxtitle <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Met
nytitle <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q3/NYT_Sheikh_with_sentiment.csv")

bigram_wc <- function(foxnews){
foxnews$text <- removeNumbers(foxnews$text)
fox_unn <- foxnews %>% unnest_tokens(word, text, token = "ngrams",
n=2) %>%
anti_join(stop_words)
Expand All @@ -44,12 +45,12 @@ bigram_wc <- function(foxnews){
return(wc)
}

fox_pos <- foxnews %>% filter(label=="Positive")
fox_neg <- foxnews %>% filter(label=="Negative")
fox_neu <- foxnews %>% filter(label=="Neutral")
fox_pos <- bigram_wc(foxnews %>% filter(label=="Positive"))
fox_neg <- bigram_wc(foxnews %>% filter(label=="Negative"))
fox_neu <- bigram_wc(foxnews %>% filter(label=="Neutral"))

nyt_pos <- nytimes %>% filter(label=="Positive")
nyt_neg <- nytimes %>% filter(label=="Negative")
nyt_neu <- nytimes %>% filter(label=="Neutral")
nyt_pos <- bigram_wc(nytimes %>% filter(label=="Positive"))
nyt_neg <- bigram_wc(nytimes %>% filter(label=="Negative"))
nyt_neu <- bigram_wc(nytimes %>% filter(label=="Neutral"))


2 changes: 1 addition & 1 deletion DataAnalysis/Q3/MakeWordCloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ make_cloud <- function(dataset, sentiment){

}

make_cloud(foxnews, "Negative")
make_cloud(nytimes, "Negative")

15 changes: 9 additions & 6 deletions DataAnalysis/Q3/Q3LinePlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@ library(dplyr)

# csv file -- change the file path here
#q1 <- read.csv('/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q1/all_tweets_emotions_with_sentiment.csv')
#foxnews <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q3/fox_news_Final_with_sentiment.csv")
#nytimes <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q3/new_york_times_Final_with_sentiment.csv")
foxtitle <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q3/FoxNews_Sheikh_with_sentiment.csv")
foxnews <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q3/fox_news_Final_with_sentiment.csv")
nytimes <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q3/new_york_times_Final_with_sentiment.csv")
#foxtitle <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q3/FoxNews_Sheikh_with_sentiment.csv")
#nytitle <- read.csv("/Volumes/GoogleDrive/My Drive/Spring 2022/Data Science Methodology/UkraineConflictOnTwitter/SentimentAnalysis/data/q3/NYT_Sheikh_with_sentiment.csv")
q1 <- foxtitle
q1 <- nytimes

#filter tweets that starts with @
q1 <- q1 %>% filter(!grepl("^@", q1$text))


## stacked bar plot ##
Expand Down Expand Up @@ -43,7 +46,7 @@ ggplot(sentiment_by_week, aes(fill=label, y=freq, x=Week, col=label)) +
geom_line(lwd=1.5) +
theme_minimal() +
theme(panel.background = element_blank()) +
ggtitle("Fox News Average Sentiment of Tweets by Week") +
ggtitle("NYTimes Average Sentiment of Tweets by Week") +
labs(x='Week', y='Frequency') +
theme(plot.title = element_text(hjust = 0.5, size=15, face='bold', margin = margin(t = 10, r = 0 , b = 10, l = 0))) +
theme(axis.title.x = element_text(face='bold', size=10, margin = margin(t = 10, b = 10, r = 0, l = 0))) +
Expand All @@ -52,6 +55,6 @@ ggplot(sentiment_by_week, aes(fill=label, y=freq, x=Week, col=label)) +
theme(axis.text.y = element_text(size=10)) +
theme(legend.title = element_text(face='bold', size=10)) +
theme(legend.text = element_text(size=8)) +
scale_x_continuous(breaks=c(1,12,19,23), labels=c("Dec 1st", "Feb 24th", "April 12th", "April 30th"))
scale_x_continuous(breaks=c(1,11,16,23), labels=c("Dec 24th", "Feb 24th", "April 7th", "May 24th"))
#scale_color_manual('label', values=c('#d9534f', '#f0ad4e', '#5cb85c', '#5cb86c', '#5cb87c', '#5cb88c', '#5cb89c'))

12 changes: 6 additions & 6 deletions DataAnalysis/Q3/trigramWordCloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ trigram_wc <- function(foxnews){
return(wc)
}

fox_pos <- foxnews %>% filter(label=="Positive")
fox_neg <- foxnews %>% filter(label=="Negative")
fox_neu <- foxnews %>% filter(label=="Neutral")
fox_pos <- trigram_wc(foxnews %>% filter(label=="Positive"))
fox_neg <- trigram_wc(foxnews %>% filter(label=="Negative"))
fox_neu <- trigram_wc(foxnews %>% filter(label=="Neutral"))

nyt_pos <- nytimes %>% filter(label=="Positive")
nyt_neg <- nytimes %>% filter(label=="Negative")
nyt_neu <- nytimes %>% filter(label=="Neutral")
nyt_pos <- trigram_wc(nytimes %>% filter(label=="Positive"))
nyt_neg <- trigram_wc(nytimes %>% filter(label=="Negative"))
nyt_neu <- trigram_wc(nytimes %>% filter(label=="Neutral"))

0 comments on commit 3eb06bf

Please sign in to comment.