1. I want to compare the reviews of TheWeeknd’s two most recently released albums After Hours and Dawn FM I find this interesting because I am a big fan of TheWeeknd and want to see what other people think of his albums.

  2. The data I am collecting is review data taken from metacritic for each album. The results of this scraping are found in the data set imported below.

library(tidyverse) #Used for working with data frames and visualizations
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.2     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.2     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── 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(tidytext) #Used for sentiment analysis
## Warning: package 'tidytext' was built under R version 4.3.2
library(textdata) #Used for sentiment analysis
## Warning: package 'textdata' was built under R version 4.3.2
reviews <- read_csv("https://myxavier-my.sharepoint.com/:u:/g/personal/leamera_xavier_edu/EYHsj5zR84JAsf7tHGMoTN8BxDh6XBUYVPKqwFwM6ldnNw?download=1")
## Rows: 1042 Columns: 3
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ","
## chr (2): review, album
## dbl (1): reviewid
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.

The first question I wanted to ask was if the same words appeared the most in reviews from the different albums. To do this I will unnest the reviews to word token then group by the album and word and then summarize the counts. I will also remove the stop words.

reviews %>% 
  unnest_tokens(word,review) %>% 
  anti_join(stop_words) %>% 
  group_by(album, word) %>% 
  summarize(n()) %>% 
  arrange(-`n()`) %>% 
  head(n=20)
## Joining with `by = join_by(word)`
## `summarise()` has grouped output by 'album'. You can override using the
## `.groups` argument.
## # A tibble: 20 × 3
## # Groups:   album [2]
##    album       word       `n()`
##    <chr>       <chr>      <int>
##  1 After Hours album        501
##  2 Dawn FM     album        483
##  3 Dawn FM     pickles      224
##  4 Dawn FM     weeknd       177
##  5 After Hours weeknd       155
##  6 Dawn FM     expand       141
##  7 After Hours expand       132
##  8 After Hours hours        132
##  9 After Hours songs        131
## 10 Dawn FM     fm           124
## 11 Dawn FM     music        112
## 12 Dawn FM     dawn         111
## 13 Dawn FM     de           110
## 14 Dawn FM     abel         102
## 15 After Hours abel          97
## 16 After Hours de            97
## 17 After Hours tracks        87
## 18 After Hours production    84
## 19 Dawn FM     hours         84
## 20 Dawn FM     time          84
#In these top 20 words, you see a lot of things you would expect such as album,
#weeknd, hours, fm, songs, and abel. When looking at these words the review data
#from the two different albums is pretty similar. One interesting thing about
#Dawn FM is the appearance of pickles. I think this is probably because of one
#review which says pickles a ton. A word that pops up a lot in the After Hours
#reviews is production which suggests that people had things to say about the 
#production of After Hours. I would assume that it is good things they are saying

The next question I wanted to explore was how the sentiments compare between the albums. To do this I will use the Bing lexicon and assign all scoreable words a positive score or a negative score based off of Bing. I will then visualize the results.

bing <- get_sentiments("bing")

review_words <- 
  reviews %>% 
  unnest_tokens(word,review) %>%
  anti_join(stop_words)
## Joining with `by = join_by(word)`
review_words %>% 
  group_by(album, word) %>% 
  summarize(n=n()) %>% 
  inner_join(bing) %>%
  filter(n > 15) %>% 
  mutate(n = ifelse(sentiment == "negative",-n,n)) %>% 
  mutate(word = reorder(word,n)) %>% 
  ggplot(aes(word, n, fill = sentiment)) +
  geom_col() +
  facet_wrap(~album) +
  coord_flip() 
## `summarise()` has grouped output by 'album'. You can override using the
## `.groups` argument.
## Joining with `by = join_by(word)`

#At first glance, it would seem like reviews for After Hours contained a lot more
#words with a negative sentiments. Looking at the negative words you find: trap,
#heartless, and blinding. Heartless and Blinding are both words that appear in 
#tracks on the album so I would consider those words neutral. Trap in this case
#could be talking about the trap genre of music. Dark appearing for both albums
#could be talking about the general theme of the albums. For Dawn FM, I would not
#consider dawn a positive word since it is in the album title. Another interesting
#thing is masterpiece appearing for Dawn FM.

The final question I wanted to address was to compare the emotional sentiments for each review between the albums. I will do this by using the same words from earlier but using the NRC lexicon instead of the Bing lexicon. I will group by album and compare the means for each emotion. Before this though I will compare the average number of words in each review since it could affect how emotional the reviews may seem.

reviews %>%
  group_by(album) %>%
  summarise(mean = mean(sapply(strsplit(review, "\\s+"), length)))
## # A tibble: 2 × 2
##   album        mean
##   <chr>       <dbl>
## 1 After Hours  42.5
## 2 Dawn FM      45.2
#Dawn FM reviews are a little longer on average but not by too much so it should
#not affect the analysis too much

nrc <- get_sentiments("nrc")

emotional_sentiments <- 
  review_words %>% 
  inner_join(nrc, by = "word", relationship = "many-to-many") %>% 
  group_by(sentiment, reviewid) %>% 
  summarize(n = n()) %>%
  pivot_wider(names_from = sentiment, values_from = n, values_fill = 0) %>% 
  mutate(positivity = positive-negative)
## `summarise()` has grouped output by 'sentiment'. You can override using the
## `.groups` argument.
review_master <- 
  left_join(reviews, emotional_sentiments, by = "reviewid") %>%
  mutate_all(~replace(., is.na(.), 0))

review_master %>% 
  group_by(album) %>% 
  summarise(across(anger:trust, mean))
## # A tibble: 2 × 11
##   album       anger anticipation disgust  fear   joy negative positive sadness
##   <chr>       <dbl>        <dbl>   <dbl> <dbl> <dbl>    <dbl>    <dbl>   <dbl>
## 1 After Hours 0.304        0.957   0.207 0.345  1       0.888     1.95   0.595
## 2 Dawn FM     0.297        1.31    0.236 0.384  1.44    0.768     2.56   0.669
## # ℹ 2 more variables: surprise <dbl>, trust <dbl>
#when looking at this table most emotions seem to be very close to each other
#a few emotions that stand out are suprise, joy, and positive. They all have 
#much higher averages for Dawn FM reviews than After Hours reviews. This could 
#suggest a more positive sentiment for Dawn FM reviews.