set.seed(12345)
options(digits = 3, scipen = 9999, width = 120, knitr.table.format = "rst")
pacman::p_load(tokenizers,stopwords,dplyr,ggplot2,
ggthemes,tidytext, qdap, tm,lda,topicmodels, ggrepel,
tidyverse,wordcloud,wordcloud2, skmeans, clue, cluster, knitr,
fpc, ldatuning, wakefield)
library(SentimentAnalysis)
library(sentimentr)
library(widyr)
library(plotly)
pacman::p_load(tidyverse, tidytext, textclean, tokenizers, markovchain)
pacman::p_load(stm, rvest, tm)
pacman::p_load(gutenbergr)
library(FactoMineR)
library(factoextra)
library(scales)
library(magrittr)
Pulling data and turning it into text:
webpage_c = read_html("https://www.ctpost.com/news/coronavirus/article/Experts-Increased-restaurant-capacity-partly-to-16081210.php")
ct0 = webpage_c %>% html_nodes("p") %>% html_text()
ct1 = data.frame(text = ct0)
head(ct1,25)
nrow(ct1)
ct2 = ct1 %>% unnest_tokens(word, text,
to_lower = T,
strip_punct = T,
strip_numeric = T
)
ct2 %>% count(word, sort = T)
ct2 = ct2 %>% anti_join(stop_words, by = "word")
head(ct2)
ct3 = cbind.data.frame(linenumber = row_number(ct2), ct2)
head(ct3)
ct3 %>% count(word, sort = T)
The plots show us that this article on Connecticut reopening restaurants contains many negative sentiments and consists of various emotions, including a lot of trust, a lot of positive, and a decent amount of joy and sadness. The fear sentiment plots are all postive.
Pulling data and turning it into text:
webpage_c = read_html("https://qns.com/2021/03/new-york-city-restaurants-can-open-up-50-indoor-dining-capacity-starting-march-19-cuomo/")
ny0 = webpage_c %>% html_nodes("p") %>% html_text()
ny1 = data.frame(text = ny0)
head(ny1,17)
nrow(ny1)
ny2 <- ny1 %>%
slice(-(11:17))
head(ny2)
ny3 = ny2 %>% unnest_tokens(word, text,
to_lower = T,
strip_punct = T,
strip_numeric = T
)
ny3 %>% count(word, sort = T)
ny3 = ny3 %>% anti_join(stop_words, by = "word")
head(ny3)
ny4 = cbind.data.frame(linenumber = row_number(ny3), ny3)
ny4 %>% count(word, sort = T)
The plots show us that this article on New York reopening restaurants contains many negative sentiments and consists of various emotions, including a lot of positive and a decent amount of fear, anticipation, and trust. The fear sentiment plots are all postive.
Pulling data and turning it into text:
webpage_c = read_html("https://www.northjersey.com/story/news/2021/03/10/nj-indoor-dining-capacity-gov-phil-murphy-covid-restaurants-salons/4642606001/")
nj0 = webpage_c %>% html_nodes("p") %>% html_text()
nj1 = data.frame(text = nj0)
head(nj1,17)
nrow(nj1)
nj2 = nj1 %>% unnest_tokens(word, text,
to_lower = T,
strip_punct = T,
strip_numeric = T
)
nj2 %>% count(word, sort = T)
nj2 = nj2 %>% anti_join(stop_words, by = "word")
head(nj2)
nj3 = cbind.data.frame(linenumber = row_number(nj2), nj2)
head(nj3)
nj3 %>% count(word, sort = T)
The plots show us that this article on New Jersey reopening restaurants contains many negative sentiments and consists of various emotions, including a lot of trust, a lot of positive, and a decent amount of joy, anticipation, and sadness. The fear sentiment plots are all postive.
Pulling data and turning it into text:
webpage_c = read_html("https://thesuffolkjournal.com/33210/news/mass-restaurants-no-longer-have-capacity-limits/")
ma0 = webpage_c %>% html_nodes("p") %>% html_text()
ma1 = data.frame(text = ma0)
head(ma1,48)
nrow(ma1)
ma2 <- ma1 %>%
slice(-(18:48))%>%
slice(-(1:4))
head(ma2)
ma3 = ma2 %>% unnest_tokens(word, text,
to_lower = T,
strip_punct = T,
strip_numeric = T
)
ma3 %>% count(word, sort = T)
ma3 = ma3 %>% anti_join(stop_words, by = "word")
head(ma3)
ma4 = cbind.data.frame(linenumber = row_number(ma3), ma3)
head(ma4)
ma4 %>% count(word, sort = T)
The plots show us that this article on Massachusetts reopening restaurants contains many negative sentiments and consists of various emotions, including a decent amount of positive, negative, fear, anticipation, and trust. The fear sentiment plots are all postive.
Pulling data and turning it into text:
webpage_c = read_html("https://www.providencejournal.com/story/entertainment/dining/2021/04/07/allowing-outdoor-dining-recoup-financially-covid-pandemic/4828603001/")
ri0 = webpage_c %>% html_nodes("p") %>% html_text()
ri1 = data.frame(text = ri0)
head(ri1,24)
nrow(ri1)
ri2 = ri1 %>% unnest_tokens(word, text,
to_lower = T,
strip_punct = T,
strip_numeric = T
)
ri2 %>% count(word, sort = T)
ri2 = ri2 %>% anti_join(stop_words, by = "word")
head(ri2)
ri3 = cbind.data.frame(linenumber = row_number(ri2), ri2)
head(ri3)
ri3 %>% count(word, sort = T)
The plots show us that this article on Rhode Islands reopening restaurants contains many negative sentiments and consists of various emotions, including a decent amount of positive, negative, fear, anticipation, and trust. The fear sentiment plots are all postive.
The comparison plot shows that most states have a variation in emotions, but each state has a high ranking in both positive and negative emotions. Positive being the highest.