library(tidytext)
## Warning: package 'tidytext' was built under R version 4.3.3
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.1.4 ✔ readr 2.1.5
## ✔ forcats 1.0.0 ✔ stringr 1.5.1
## ✔ ggplot2 3.4.4 ✔ tibble 3.2.1
## ✔ lubridate 1.9.3 ✔ tidyr 1.3.1
## ✔ purrr 1.0.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(textdata)
## Warning: package 'textdata' was built under R version 4.3.3
library(wordcloud2)
## Warning: package 'wordcloud2' was built under R version 4.3.3
library(wordcloud)
## Warning: package 'wordcloud' was built under R version 4.3.3
## Loading required package: RColorBrewer
library(dplyr)
nrc <- get_sentiments("nrc")
load("C:/Users/bmpav/OneDrive/Desktop/geocoded_tweets.rda")
View(geocoded_tweets)
bing <- get_sentiments("bing")
tweet_bing <- geocoded_tweets %>% inner_join(get_sentiments("bing"))
## Joining with `by = join_by(word)`
## Warning in inner_join(., get_sentiments("bing")): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 146965 of `x` matches multiple rows in `y`.
## ℹ Row 27 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
## "many-to-many"` to silence this warning.
tweet_nrc <- geocoded_tweets %>% inner_join(get_sentiments("nrc"))
## Joining with `by = join_by(word)`
## Warning in inner_join(., get_sentiments("nrc")): Detected an unexpected many-to-many relationship between `x` and `y`.
## ℹ Row 9 of `x` matches multiple rows in `y`.
## ℹ Row 5 of `y` matches multiple rows in `x`.
## ℹ If a many-to-many relationship is expected, set `relationship =
## "many-to-many"` to silence this warning.
sad <- tweet_nrc %>% filter(sentiment=='sadness') %>% group_by(word) %>% summarize(freq = mean(freq)) %>% arrange(desc(freq))
View(tweet_nrc)
joy <- tweet_nrc %>% filter(sentiment == "joy") %>% group_by(word) %>% summarize(freq = mean(freq)) %>% arrange(desc(freq))
wordcloud(words = joy$word, freq = joy$freq, min.freq = 5, max.words = 100, random.order = T, colors = brewer.pal(8,"Accent"))

wordcloud2(joy, size=1.2, shape='diamond') %>% htmlwidgets::prependContent(htmltools::tags$h1("Wordcloud - 21MIC0065"))
Wordcloud - 21MIC0065
joy %>% top_n(15)%>% mutate(word=reorder(word,freq)) %>% ggplot(aes(x=word, y=freq)) + geom_col() +labs(title="Frequency plot of joywords - 21MIC0065", x= "Joy_words", y="Frequency")
## Selecting by freq

joy %>% top_n(15)%>% mutate(word=reorder(word,freq)) %>% ggplot(aes(x=word, y=freq)) + geom_col() + coord_flip() + labs(title="Frequency plot of joywords - 21MIC0065", x= "Joy_words", y="Frequency")
## Selecting by freq
