Skip to content

Commit

Permalink
some new graphs and stuff
Browse files Browse the repository at this point in the history
  • Loading branch information
sheikhshafayat committed May 27, 2022
1 parent cfd2c15 commit b4b3222
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 5 deletions.
4 changes: 2 additions & 2 deletions DataAnalysis/Q3/BigramWordCloud.R
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ bigram_wc <- function(foxnews){
bg_fox <- fox_unn %>%
separate(word, c("word1", "word2"), sep=" ")

avoid_list <- c("russia", "ukraine", "user", "http", "fox", "york")
avoid_list <- c("russia", "ukraine", "user", "http", "fox", "york", "tucker")
filter_bg_fox <- bg_fox %>%
filter(!word1 %in% stop_words$word) %>%
filter(!word2 %in% stop_words$word) %>%
Expand Down Expand Up @@ -52,4 +52,4 @@ nyt_pos <- nytimes %>% filter(label=="Positive")
nyt_neg <- nytimes %>% filter(label=="Negative")
nyt_neu <- nytimes %>% filter(label=="Neutral")

filter_by_date <-

Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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, "Neutral")
make_cloud(foxnews, "Negative")

Binary file added DataAnalysis/Q3/NYT Avg Sentiment Over Week.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed DataAnalysis/Q3/NYTimesTitleSentiment.png
Binary file not shown.
4 changes: 2 additions & 2 deletions DataAnalysis/Q3/Q3LinePlot.R
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,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("NY Times Average Emotions of Tweets by Week") +
ggtitle("Fox News 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 +52,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,11,16,23), labels=c("Dec 24th", "Feb 24th", "April 7th", "May 24th"))
scale_x_continuous(breaks=c(1,12,19,23), labels=c("Dec 1st", "Feb 24th", "April 12th", "April 30th"))
#scale_color_manual('label', values=c('#d9534f', '#f0ad4e', '#5cb85c', '#5cb86c', '#5cb87c', '#5cb88c', '#5cb89c'))

3 changes: 3 additions & 0 deletions DataAnalysis/Q3/Q3RAnalysisSheikh.R
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,9 @@ ggplot(allSent, aes(x=Sentiment, y=Percentage, fill=Source)) +
geom_bar(stat="identity", width = 1, position = position_dodge()) +
theme(panel.background = element_blank()) +
ggtitle("Media Outlet Tweet and Reply Sentiment Comparison") +
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=12, margin = margin(t = 10, b = 10, r = 0, l = 0))) +
theme(axis.title.y = element_text(face='bold', size=12, margin = margin(t = 0, b = 0, r = 10, l = 10))) +
scale_fill_manual(values=c("#fc4949", "#1a94eb"))

###############################################################################
Expand Down
Binary file added DataAnalysis/Q3/bigramnyt.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added DataAnalysis/Q3/foxnegbigram.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
56 changes: 56 additions & 0 deletions DataAnalysis/Q3/trigramWordCloud.R
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
library(pacman) #my package manager

#load necessary packages
p_load(ggplot2)
p_load(dplyr)
p_load(reshape2)
p_load(gridExtra)
p_load(stringr)
p_load(tidytext)
p_load(tidyr)
p_load(wordcloud)
p_load(tm)

####Loading all the data
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")

trigram_wc <- function(foxnews){
fox_unn <- foxnews %>% unnest_tokens(word, text, token = "ngrams",
n=3) %>%
anti_join(stop_words)
bg_fox <- fox_unn %>%
separate(word, c("word1", "word2", "word3"), sep=" ")

avoid_list <- c("russia", "ukraine", "user", "http", "fox", "york")
filter_bg_fox <- bg_fox %>%
filter(!word1 %in% stop_words$word) %>%
filter(!word2 %in% stop_words$word) %>%
filter(!word3 %in% stop_words$word) %>%
filter(!word1 %in% avoid_list) %>%
filter(!word2 %in% avoid_list) %>%
filter(!word3 %in% avoid_list)

count_bg <- filter_bg_fox %>%
group_by(word1, word2) %>%
tally(sort = TRUE)

count_bg <- as.data.frame(count_bg)

count_bg$bigram <- paste(count_bg$word1, count_bg$word2, sep=" ")
wc <- wordcloud(words = count_bg$bigram, freq = count_bg$n, min.freq = 1, max.words=200, random.order=FALSE, rot.per=0.35,
colors=brewer.pal(8, "Dark2"))

return(wc)
}

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

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

0 comments on commit b4b3222

Please sign in to comment.