This final project will explore Kendrick Lamar’s discography

I will explore how Kendrick Lamar’s music has become less upbeat and slightly more depressing over the course of his four studio albums. Lamar’s sound in a couple of his songs has become more somber and less upbeat as his career has progressed due to being in the spotlight and dealing with addiction and struggling with his mental health. According to https://hiphopunrapped.com/articles-hiphop-rap-socialissues/the-real-meaning-behind-kendrick-lamar-u-survivorsguilt-impostorsyndrome, Lamar experienced an inner conflict as he questioned his role as a public figure; he didn’t know how he could perform to fans across the globe while feeling guilty for being unable to help his friend and family members who were struggling with death and pregnancy in Compton. Following his first album, “Kendrick fell into a deep depression that gave us his next album, To Pimp A Butterfly. I will be examining three of his studio albums, good kid, m.A.A.d city (2012), To Pimp A Butterfly (2015), and DAMN. (2017), and his one compilation album untitled unmastered. (2016) with the help of online sources and Spotify. Analyzing four of his albums can be useful to show how his music has changed and how his fame has increased over time. I will also examine the energy, danceability and valence rates of each album to see if there are significant changes in these rates from 2012 to 2017. I will use Spotify API and research from the internet to obtain my necessary API. I received Lamar’s lyrics in a JSON file from Professor Walsh so I turned it into a datafile.

I hypothesize that Lamar’s albums started off very positive, and as he gradually became more famous and released more music, his albums became more negative and depressing due to his role in the public spotlight while grappling with social and personal issues.

Pictured above is Kendrick Lamar. Image from lithub.com

This document will include explicit content.

First, I will download the necessary packages:

library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.6     ✓ dplyr   1.0.8
## ✓ tidyr   1.2.0     ✓ stringr 1.4.0
## ✓ readr   2.1.2     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
library(spotifyr)
library(tidytext)
## 
## Attaching package: 'tidytext'
## The following object is masked from 'package:spotifyr':
## 
##     tidy
library(textdata)
library(ggjoy)
## Loading required package: ggridges
## The ggjoy package has been deprecated. Please switch over to the
## ggridges package, which provides the same functionality. Porting
## guidelines can be found here:
## https://github.com/clauswilke/ggjoy/blob/master/README.md
library(ggridges)
library(knitr)
library(genius)
library(ggthemes)
library(jsonlite)
## 
## Attaching package: 'jsonlite'
## The following object is masked from 'package:purrr':
## 
##     flatten
library(vembedr)
library(wordcloud2)

I uploaded the code to tell R where to look for my Kendrick Lamar folder.

setwd("~/Desktop/KL")

First I have a video of young Lamar talking about his music, dated October 20, 2010.

embed_youtube("https://www.youtube.com/watch?v=6_WIciXu3Tg")

Next, I am going to look at each album!

good kid, m.A.A.d city (2012)

To begin, I turned the album into a datafile.

kid <- fromJSON("Lyrics_goodkidm.A.A.dcity.json")
as.data.frame(kid) -> kid_df
kid_df$tracks.song -> kidlyrics

kidlyrics %>%
  unnest_tokens(word, lyrics) -> kid

Let’s look at how many words are in this album.

kid %>% 
  count()
##       n
## 1 12089

12089 words are in good kid, m.A.A.d city. Now lets look at the most popular words.

kid %>%
  anti_join(stop_words) %>%
  count(word, sort = TRUE) %>% 
  filter(!word %in% c("tahm", "igh","kendrick", "lamar", "verse", "chorus", "1", "2")) %>% 
  head(20) %>%
  knitr::kable()
## Joining, by = "word"
word n
nigga 77
love 59
real 58
sing 44
bitch 39
shit 38
life 35
drank 34
feel 33
fuck 33
promise 31
kill 30
song 28
city 27
vibe 27
ya 27
gon 26
bish 24
niggas 24
day 22
kid %>%
  anti_join(stop_words) %>%
  count(word, sort = TRUE) %>% 
  inner_join(get_sentiments("afinn")) %>%
  inner_join(get_sentiments("bing")) %>% 
  filter(!word %in% c("tahm", "igh","kendrick", "lamar", "verse", "chorus", "1", "2")) %>% 
  head(20) %>% 
  knitr::kable() -> kidsentiment
## Joining, by = "word"
## Joining, by = "word"
## Joining, by = "word"
kidsentiment  
word n value sentiment
love 59 3 positive
bitch 39 -5 negative
shit 38 -4 negative
fuck 33 -4 negative
promise 31 1 positive
kill 30 -3 negative
damn 21 -4 negative
tired 15 -2 negative
die 12 -3 negative
hate 8 -3 negative
pain 7 -2 negative
top 7 2 positive
bad 6 -3 negative
dead 6 -3 negative
dick 6 -4 negative
free 6 1 positive
killed 6 -3 negative
broke 5 -1 negative
proud 5 2 positive
rich 5 2 positive

‘Love’ is one of the most popular words, which makes sense because this album is a coming-of-age story about battling growing up and gang violence while trying to love oneself. The album includes a song in which Lamar reflects on being baptized and finding himself. In addition, this album consists of songs that discuss gang life and the struggle of deciding whether to stray away from the gang and have no protection, or stay with the gang and get involved in violence. Thus, it is appropriate that the songs featured in this album include some negative words. ’N***a’ is the most popular word on the album; it is a term that some Black individuals use to refer to their fellow African-Americans and is commonly used in rap songs.

Bitch has a negative sentiment of -5, which means that it is an aggressive term that carries a lot of value. ‘Love’ has a sentiment of 3, which is appropriate given that this album is about Kendrick’s attempt to find himself. Overall, this album seems to have a more negative sentiment. The upbeat sound of Kendrick’s songs contrast, this negative sentiment, and the many challenges he faces as he matures.

Let’s download the album from the Spotify API

Sys.setenv(SPOTIFY_CLIENT_ID = 'cfe386975d294646aca48ec58729cb9c')
Sys.setenv(SPOTIFY_CLIENT_SECRET = '8a254c0dc3e945cf85541e94995cda31')

access_token <- get_spotify_access_token()
kendricklamar <- get_artist_audio_features('Kendrick Lamar')
kendricklamar %>% 
  filter(album_name %in% "good kid, m.A.A.d city")-> kidalbum
kendricklamar %>% 
  filter(album_name %in% "good kid, m.A.A.d city") %>% 
  select(danceability, album_name, energy, track_name) %>% 
  kable()
danceability album_name energy track_name
0.503 good kid, m.A.A.d city 0.508 Sherane a.k.a Master Splinter’s Daughter
0.587 good kid, m.A.A.d city 0.698 Bitch, Don’t Kill My Vibe
0.546 good kid, m.A.A.d city 0.651 Backseat Freestyle
0.555 good kid, m.A.A.d city 0.611 The Art of Peer Pressure
0.716 good kid, m.A.A.d city 0.531 Money Trees
0.779 good kid, m.A.A.d city 0.572 Poetic Justice
0.451 good kid, m.A.A.d city 0.831 good kid
0.487 good kid, m.A.A.d city 0.729 m.A.A.d city
0.716 good kid, m.A.A.d city 0.485 Swimming Pools (Drank) - Extended Version
0.654 good kid, m.A.A.d city 0.753 Sing About Me, I’m Dying Of Thirst
0.652 good kid, m.A.A.d city 0.458 Real
0.342 good kid, m.A.A.d city 0.907 Compton
0.616 good kid, m.A.A.d city 0.778 Bitch, Don’t Kill My Vibe - Remix
0.567 good kid, m.A.A.d city 0.502 Sherane a.k.a Master Splinter’s Daughter
0.614 good kid, m.A.A.d city 0.685 Bitch, Don’t Kill My Vibe
0.585 good kid, m.A.A.d city 0.645 Backseat Freestyle
0.563 good kid, m.A.A.d city 0.561 The Art of Peer Pressure
0.715 good kid, m.A.A.d city 0.537 Money Trees
0.784 good kid, m.A.A.d city 0.561 Poetic Justice
0.564 good kid, m.A.A.d city 0.833 good kid
0.462 good kid, m.A.A.d city 0.676 m.A.A.d city
0.671 good kid, m.A.A.d city 0.474 Swimming Pools (Drank) - Extended Version
0.575 good kid, m.A.A.d city 0.748 Sing About Me, I’m Dying Of Thirst
0.666 good kid, m.A.A.d city 0.457 Real
0.344 good kid, m.A.A.d city 0.911 Compton
0.648 good kid, m.A.A.d city 0.772 Bitch, Don’t Kill My Vibe - Remix
0.503 good kid, m.A.A.d city 0.508 Sherane a.k.a Master Splinter’s Daughter
0.587 good kid, m.A.A.d city 0.698 Bitch, Don’t Kill My Vibe
0.546 good kid, m.A.A.d city 0.651 Backseat Freestyle
0.555 good kid, m.A.A.d city 0.611 The Art of Peer Pressure
0.716 good kid, m.A.A.d city 0.531 Money Trees
0.779 good kid, m.A.A.d city 0.572 Poetic Justice
0.451 good kid, m.A.A.d city 0.831 good kid
0.487 good kid, m.A.A.d city 0.729 m.A.A.d city
0.716 good kid, m.A.A.d city 0.485 Swimming Pools (Drank) - Extended Version
0.654 good kid, m.A.A.d city 0.753 Sing About Me, I’m Dying Of Thirst
0.652 good kid, m.A.A.d city 0.458 Real
0.342 good kid, m.A.A.d city 0.907 Compton
0.567 good kid, m.A.A.d city 0.502 Sherane a.k.a Master Splinter’s Daughter
0.614 good kid, m.A.A.d city 0.685 Bitch, Don’t Kill My Vibe
0.585 good kid, m.A.A.d city 0.645 Backseat Freestyle
0.563 good kid, m.A.A.d city 0.561 The Art of Peer Pressure
0.715 good kid, m.A.A.d city 0.537 Money Trees
0.784 good kid, m.A.A.d city 0.561 Poetic Justice
0.564 good kid, m.A.A.d city 0.833 good kid
0.462 good kid, m.A.A.d city 0.676 m.A.A.d city
0.671 good kid, m.A.A.d city 0.474 Swimming Pools (Drank) - Extended Version
0.575 good kid, m.A.A.d city 0.748 Sing About Me, I’m Dying Of Thirst
0.666 good kid, m.A.A.d city 0.457 Real
0.344 good kid, m.A.A.d city 0.911 Compton
0.503 good kid, m.A.A.d city 0.508 Sherane a.k.a Master Splinter’s Daughter
0.587 good kid, m.A.A.d city 0.698 Bitch, Don’t Kill My Vibe
0.546 good kid, m.A.A.d city 0.651 Backseat Freestyle
0.555 good kid, m.A.A.d city 0.611 The Art of Peer Pressure
0.716 good kid, m.A.A.d city 0.531 Money Trees
0.779 good kid, m.A.A.d city 0.572 Poetic Justice
0.451 good kid, m.A.A.d city 0.831 good kid
0.487 good kid, m.A.A.d city 0.729 m.A.A.d city
0.716 good kid, m.A.A.d city 0.485 Swimming Pools (Drank) - Extended Version
0.654 good kid, m.A.A.d city 0.753 Sing About Me, I’m Dying Of Thirst
0.652 good kid, m.A.A.d city 0.458 Real
0.342 good kid, m.A.A.d city 0.907 Compton
0.616 good kid, m.A.A.d city 0.778 Bitch, Don’t Kill My Vibe - Remix
0.667 good kid, m.A.A.d city 0.814 Bitch, Don’t Kill My Vibe - International Remix / Explicit Version
0.503 good kid, m.A.A.d city 0.508 Sherane a.k.a Master Splinter’s Daughter
0.587 good kid, m.A.A.d city 0.698 Bitch, Don’t Kill My Vibe
0.546 good kid, m.A.A.d city 0.651 Backseat Freestyle
0.555 good kid, m.A.A.d city 0.611 The Art of Peer Pressure
0.716 good kid, m.A.A.d city 0.531 Money Trees
0.779 good kid, m.A.A.d city 0.572 Poetic Justice
0.451 good kid, m.A.A.d city 0.831 good kid
0.487 good kid, m.A.A.d city 0.729 m.A.A.d city
0.716 good kid, m.A.A.d city 0.485 Swimming Pools (Drank) - Extended Version
0.654 good kid, m.A.A.d city 0.753 Sing About Me, I’m Dying Of Thirst
0.652 good kid, m.A.A.d city 0.458 Real
0.342 good kid, m.A.A.d city 0.907 Compton
0.625 good kid, m.A.A.d city 0.773 Bitch, Don’t Kill My Vibe - Remix
0.567 good kid, m.A.A.d city 0.502 Sherane a.k.a Master Splinter’s Daughter
0.614 good kid, m.A.A.d city 0.685 Bitch, Don’t Kill My Vibe
0.585 good kid, m.A.A.d city 0.645 Backseat Freestyle
0.563 good kid, m.A.A.d city 0.561 The Art of Peer Pressure
0.715 good kid, m.A.A.d city 0.537 Money Trees
0.784 good kid, m.A.A.d city 0.561 Poetic Justice
0.564 good kid, m.A.A.d city 0.833 good kid
0.462 good kid, m.A.A.d city 0.676 m.A.A.d city
0.671 good kid, m.A.A.d city 0.474 Swimming Pools (Drank) - Extended Version
0.575 good kid, m.A.A.d city 0.748 Sing About Me, I’m Dying Of Thirst
0.666 good kid, m.A.A.d city 0.457 Real
0.344 good kid, m.A.A.d city 0.911 Compton
0.648 good kid, m.A.A.d city 0.772 Bitch, Don’t Kill My Vibe - Remix

The energy on this album is low for some songs likely because of their slower tempo. The song with the lowest energy is “Bitch Don’t Kill My Vibe - International Remix”, which is slower than the original song, ‘Bitch Don’t Kill My Vibe’. Overall, the album has a good energy because many of Kendrick’s songs have an upbeat tune and reflect the musical energy that Kendrick’s fans enjoy listening to. The energy is unexpected given that there are a lot of negative sentiment words on the album. For example, ‘bitch’ is one of the common negative terms featured in the album and is frequently used in his song, “Bitch Don’t Kill My Vibe”. There are a couple of songs, such as “Compton” that have a high energy rate and very upbeat tempo. Overall, this debut album set off Lamar’s career and sparked his popularity amongst fans across the world.

kidalbum%>% 
arrange(desc(energy))%>%
  ggplot(aes(track_name, energy, fill= track_name)) + geom_col() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),legend.position = "none") + 
  coord_flip() +
   ggtitle("Energy of Kendrick Lamar's Album, good kid, m.A.A.d city")

Now let’s look at the albums valence.

kidalbum %>%
  filter(album_name %in% "good kid, m.A.A.d city") %>%
  ggplot(aes(reorder(track_name, valence), valence) ) + geom_col() +
  coord_flip() +
  theme_economist()+
   ggtitle("Valence of Kendrick Lamar's Album, good kid, m.A.A.d city")

The valence of this album starts off high, and then gradually decreases to zero. This shows that the songs with higher valence are more upbeat, happier songs, and the album gradually becomes more depressing. “Poetic Justice” and “Backseat Freestyle” have the highest valence rates, which aligns with their upbeat tempos.

To Pimp A Butterfly (2015)

butterfly <- fromJSON("Lyrics_ToPimpaButterfly.json")
as.data.frame(butterfly) -> butterfly_df
butterfly_df$tracks.song -> butterflylyrics

butterflylyrics %>%
  unnest_tokens(word, lyrics) -> butterfly 

Let’s look at the word count and the most popular words featured in Kendrick Lamar’s album, To Pimp A Butterfly.

butterfly %>% 
count()
##       n
## 1 13682
butterfly %>%
  anti_join(stop_words) %>%
  count(word, sort = TRUE) %>% 
  filter(!word %in% c("tahm", "igh","kendrick", "lamar", "verse", "chorus", "1", "2")) %>% 
  head(20) %>%
  knitr::kable()
## Joining, by = "word"
word n
nigga 90
love 62
shit 53
black 46
gon 43
fuck 35
gotta 35
wanna 32
fan 31
walls 31
i’m 30
alright 29
talk 29
boo 27
lie 27
time 27
zoom 27
funk 26
niggas 25
hit 24

The word count on this album is 13682. This album has the same two most popular words as Lamar’s first album, good kid, m.A.A.d city. This is not surprising because Kendrick Lamar tries to preach self-love in his albums, while also discussing heavy topics such as racism, materialism, violence, substance use, mental health issues, and oppression. Like good kid, m.A.A.d city, the most popular word on this album is the n-word. While this is a sensitive and offensive word in our society, it is important to talk about it within the context of gangs, because Black artists in rap culture see it as a symbol of brotherhood and a term of endearment for their peers. According to Wikipedia, https://en.wikipedia.org/wiki/To_Pimp_a_Butterfly, “lyrically this album features political commentary and personal themes concerning African-American culture, racial inequality, depression, and institutional depression.”

Here is a wordcloud to visualize.

butterfly %>% 
  count(word, sort = TRUE) %>% 
  anti_join(stop_words) %>% 
  filter(!word %in% c("tahm", "igh", "chorus", "verse", "kendrick", "lamar","1", "2")) %>% 
  wordcloud2()
## Joining, by = "word"
butterfly %>%
  anti_join(stop_words) %>%
  count(word, sort = TRUE) %>% 
  inner_join(get_sentiments("afinn")) %>%
  inner_join(get_sentiments("bing")) %>% 
  filter(!word %in% c("tahm", "igh","kendrick", "lamar", "verse", "chorus", "1", "2")) %>% 
  head(20) %>%
  knitr::kable() -> butterflysentiment
## Joining, by = "word"
## Joining, by = "word"
## Joining, by = "word"
butterflysentiment
word n value sentiment
love 62 3 positive
shit 53 -4 negative
fuck 35 -4 negative
loving 23 2 positive
bitch 19 -5 negative
dead 13 -3 negative
hard 12 -1 negative
free 11 1 positive
hate 11 -3 negative
dick 10 -4 negative
impress 10 3 positive
bad 7 -3 negative
kill 7 -3 negative
rich 7 2 positive
mad 6 -3 negative
poor 6 -2 negative
crazy 5 -2 negative
hurt 5 -2 negative
mistakes 5 -2 negative
bullshit 4 -4 negative

Love has a sentiment of 3 and is use 62 times within the album. It carries a lot of positive feeling. However, this album is overall negative because the term, ’n***a’, has a sentiment of -5 and ‘shit’ and ‘fuck’ both have a sentiment of -4. The low sentiments of these words and their frequent use in the album results in the album having low energy and a more depressing sound.

Spotify API

kendricklamar %>% 
  filter(album_name %in% "To Pimp A Butterfly")-> butterflyalbum

kendricklamar %>% 
  filter(album_name %in% "To Pimp A Butterfly") %>% 
  select(danceability, album_name, energy, track_name) %>% 
  kable()
danceability album_name energy track_name
0.509 To Pimp A Butterfly 0.787 Wesley’s Theory
0.526 To Pimp A Butterfly 0.896 For Free? - Interlude
0.884 To Pimp A Butterfly 0.657 King Kunta
0.539 To Pimp A Butterfly 0.731 Institutionalized
0.752 To Pimp A Butterfly 0.489 These Walls
0.406 To Pimp A Butterfly 0.798 u
0.796 To Pimp A Butterfly 0.766 Alright
0.301 To Pimp A Butterfly 0.686 For Sale? - Interlude
0.615 To Pimp A Butterfly 0.743 Momma
0.731 To Pimp A Butterfly 0.661 Hood Politics
0.624 To Pimp A Butterfly 0.729 How Much A Dollar Cost
0.665 To Pimp A Butterfly 0.558 Complexion (A Zulu Love)
0.553 To Pimp A Butterfly 0.852 The Blacker The Berry
0.443 To Pimp A Butterfly 0.635 You Ain’t Gotta Lie (Momma Said)
0.541 To Pimp A Butterfly 0.809 i
0.567 To Pimp A Butterfly 0.525 Mortal Man
0.509 To Pimp A Butterfly 0.787 Wesley’s Theory
0.526 To Pimp A Butterfly 0.896 For Free? - Interlude
0.884 To Pimp A Butterfly 0.657 King Kunta
0.539 To Pimp A Butterfly 0.731 Institutionalized
0.752 To Pimp A Butterfly 0.489 These Walls
0.406 To Pimp A Butterfly 0.798 u
0.796 To Pimp A Butterfly 0.766 Alright
0.301 To Pimp A Butterfly 0.686 For Sale? - Interlude
0.615 To Pimp A Butterfly 0.743 Momma
0.731 To Pimp A Butterfly 0.661 Hood Politics
0.624 To Pimp A Butterfly 0.729 How Much A Dollar Cost
0.665 To Pimp A Butterfly 0.558 Complexion (A Zulu Love)
0.553 To Pimp A Butterfly 0.852 The Blacker The Berry
0.443 To Pimp A Butterfly 0.635 You Ain’t Gotta Lie (Momma Said)
0.541 To Pimp A Butterfly 0.809 i
0.567 To Pimp A Butterfly 0.525 Mortal Man
0.547 To Pimp A Butterfly 0.778 Wesley’s Theory
0.489 To Pimp A Butterfly 0.892 For Free? - Interlude
0.889 To Pimp A Butterfly 0.639 King Kunta
0.540 To Pimp A Butterfly 0.745 Institutionalized
0.647 To Pimp A Butterfly 0.484 These Walls
0.499 To Pimp A Butterfly 0.783 u
0.796 To Pimp A Butterfly 0.750 Alright
0.364 To Pimp A Butterfly 0.697 For Sale? - Interlude
0.606 To Pimp A Butterfly 0.737 Momma
0.756 To Pimp A Butterfly 0.627 Hood Politics
0.637 To Pimp A Butterfly 0.732 How Much A Dollar Cost
0.654 To Pimp A Butterfly 0.558 Complexion (A Zulu Love)
0.534 To Pimp A Butterfly 0.841 The Blacker The Berry
0.430 To Pimp A Butterfly 0.631 You Ain’t Gotta Lie (Momma Said)
0.552 To Pimp A Butterfly 0.777 i
0.523 To Pimp A Butterfly 0.516 Mortal Man
0.547 To Pimp A Butterfly 0.778 Wesley’s Theory
0.489 To Pimp A Butterfly 0.892 For Free? - Interlude
0.889 To Pimp A Butterfly 0.639 King Kunta
0.540 To Pimp A Butterfly 0.745 Institutionalized
0.647 To Pimp A Butterfly 0.484 These Walls
0.499 To Pimp A Butterfly 0.783 u
0.796 To Pimp A Butterfly 0.750 Alright
0.364 To Pimp A Butterfly 0.697 For Sale? - Interlude
0.606 To Pimp A Butterfly 0.737 Momma
0.756 To Pimp A Butterfly 0.627 Hood Politics
0.637 To Pimp A Butterfly 0.732 How Much A Dollar Cost
0.654 To Pimp A Butterfly 0.558 Complexion (A Zulu Love)
0.534 To Pimp A Butterfly 0.841 The Blacker The Berry
0.430 To Pimp A Butterfly 0.631 You Ain’t Gotta Lie (Momma Said)
0.552 To Pimp A Butterfly 0.777 i
0.523 To Pimp A Butterfly 0.516 Mortal Man

We are going to look at danceability for this album, because it is his most liked album.

butterflyalbum %>%
  arrange(desc(danceability))%>%
  ggplot(aes(track_name, danceability, fill= track_name)) + geom_col() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),legend.position = "none") + 
  coord_flip()+
  ggtitle("Danceability of Kendrick Lamar's Album, To Pimp A Butterfly")

The danceability on this album is somewhat scattered but it is primarily high, which is appropriate given that it is Lamar’s most popular album, according to https://cw.ua.edu/83750/culture/culture-pick-ranking-kendrick-lamars-albums/. Although this album has a more negative sentiment, it has very high danceability rates. “King Kunta” is an upbeat song with a fast tempo and has the highest danceability rate on this album. Overall, this album was popular on the charts, according to https://www.latimes.com/entertainment/music/posts/la-et-ms-kendrick-lamar-tops-billboard-album-chart-to-pimp-a-butterfly-20150326-story.html#:~:text=But%20given%20the%20widespread%20commotion,1.&text=Lamar’s%20third%20studio%20LP%20topped,streams%2C%20according%20to%20Nielsen%20Music., and has great danceability rates.

butterflyalbum %>%
  filter(album_name %in% "To Pimp A Butterfly") %>%
  ggplot(aes(reorder(track_name, valence), valence) ) + geom_col() +
  coord_flip() +
  theme_economist() +
  ggtitle("Valence of Kendrick Lamar's Album, To Pimp A Butterfly")

This album has an overall high valence with all songs being above 1 on a scale. This means that this album is predominantly happy and does not have many depressing tracks. This is expected from the danceability rates, but is interesting to see since the album has an overall negative sentiment.

untitled unmastered. (2016)

unmastered <- fromJSON("Lyrics_untitledunmastered..json")
as.data.frame(unmastered) -> unmastered_df
unmastered_df$tracks.song -> unmasteredlyrics

unmasteredlyrics %>%
  unnest_tokens(word, lyrics) -> unmastered
unmastered %>% 
  count()
##      n
## 1 4988

It’s important to note that this album has significantly less words than his other three albums, because this album only consists of eight songs.that range from 2 minutes to 8 minutes. Let’s see the most popular words.

unmastered %>%
  anti_join(stop_words) %>%
  count(word, sort = TRUE) %>% 
  inner_join(get_sentiments("afinn")) %>% 
  inner_join(get_sentiments("bing")) %>% 
  filter(!word %in% c("tahm", "igh","kendrick", "lamar", "verse", "chorus", "1", "2")) %>% 
  head(20) %>%
  knitr::kable() -> unmasteredsentiment
## Joining, by = "word"
## Joining, by = "word"
## Joining, by = "word"

The most popular words are “levitate”, “explain”, “pimp”. This album is a compilation of eight demos of unused songs from Lamar’s To Pimp A Butterfly recording sessions. He released this album to be a direct response to fans who were clamoring for more music after Lamar’s Grammy performance back in February. Looking at the sentiment of the album might give us a better sense of the mood of the untitled unmastered. album. It is his least liked album according to https://cw.ua.edu/83750/culture/culture-pick-ranking-kendrick-lamars-albums/ . Lyrically, this album consists of politically charged and philosophical themes, as well as his experimentation with new sounds and styles.

Here is a sentiment analysis.

unmasteredsentiment
word n value sentiment
bitch 15 -5 negative
die 13 -3 negative
shit 11 -4 negative
fuck 8 -4 negative
bad 6 -3 negative
love 6 3 positive
top 6 2 positive
broke 5 -1 negative
crazy 5 -2 negative
luck 5 3 positive
wrong 5 -2 negative
sad 4 -2 negative
crash 3 -2 negative
fear 3 -2 negative
free 3 1 positive
hate 3 -3 negative
stuck 3 -2 negative
blessing 2 3 positive
broken 2 -1 negative
drag 2 -1 negative

untitled unmastered. has a negative sentiment which makes sense since there has been a theme that all of his albums are negative thus far. Most of his albums are most likely negative due to having political and philosophical themes Bitch again has a low sentiment of -5 which is the same as it was in To Pimp A Butterfly. Love is also in this album but is not one of the most popular words, but still has a high sentiment.

Here is word cloud to visualize.

unmastered %>% 
  count(word, sort = TRUE) %>% 
  anti_join(stop_words) %>% 
  filter(!word %in% c("tahm", "igh", "chorus", "verse", "kendrick", "lamar","1", "2")) %>% 
  wordcloud2()
## Joining, by = "word"

Spotify API

kendricklamar %>% 
  filter(album_name %in% "untitled unmastered.")-> unmasteredalbum

kendricklamar %>% 
  filter(album_name %in% "untitled unmastered.") %>% 
  select(danceability, album_name, energy, track_name) %>% 
  kable()
danceability album_name energy track_name
0.570 untitled unmastered. 0.584 untitled 01 | 08.19.2014.
0.667 untitled unmastered. 0.508 untitled 02 | 06.23.2014.
0.813 untitled unmastered. 0.549 untitled 03 | 05.28.2013.
0.512 untitled unmastered. 0.128 untitled 04 | 08.14.2014.
0.461 untitled unmastered. 0.620 untitled 05 | 09.21.2014.
0.669 untitled unmastered. 0.541 untitled 06 | 06.30.2014.
0.567 untitled unmastered. 0.463 untitled 07 | 2014 - 2016
0.850 untitled unmastered. 0.524 untitled 08 | 09.06.2014.
0.574 untitled unmastered. 0.571 untitled 01 | 08.19.2014.
0.613 untitled unmastered. 0.494 untitled 02 | 06.23.2014.
0.829 untitled unmastered. 0.544 untitled 03 | 05.28.2013.
0.606 untitled unmastered. 0.110 untitled 04 | 08.14.2014.
0.470 untitled unmastered. 0.644 untitled 05 | 09.21.2014.
0.653 untitled unmastered. 0.548 untitled 06 | 06.30.2014.
0.536 untitled unmastered. 0.451 untitled 07 | 2014 - 2016
0.846 untitled unmastered. 0.522 untitled 08 | 09.06.2014.
unmasteredalbum %>%
  arrange(desc(energy))%>%
  ggplot(aes(track_name, energy, fill= track_name)) + geom_col() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),legend.position = "none") + 
  coord_flip()+
  ggtitle("Energy of Kendrick Lamar's Album, untitled unmastered.")

I decided to look at energy for this album. The energy rate is mostly high with every song except ‘untitled 04’. This album is his least liked album but still has very high energy rate and upbeat tune. It is important to note that “Untitled 05” has the highest energy rate, as it was the least dark song on this album. Overall, this album was not as popular but has good energy.

unmasteredalbum %>%
  filter(album_name %in% "untitled unmastered.") %>%
  ggplot(aes(reorder(track_name, valence), valence) ) + geom_col() +
  coord_flip() +
  theme_economist()+
  ggtitle("Valence of Kendrick Lamar's Album, untitled unmastered.")

The valence on this album is low in general since they are all below 1. It has a somewhat high valence which means that it happy but is also a little depressive. This is interesting to see from the high energy rates but has a low valence, which means it is more of a depressing album overall.

DAMN. (2017)

damn <- fromJSON("Lyrics_DAMN.json")
as.data.frame(damn) -> damn_df
damn_df$tracks.song -> damnlyrics

damnlyrics %>%
  unnest_tokens(word, lyrics) -> damn 

Now lets look at the word count and most popular words.

damn %>% 
  count()
##      n
## 1 9060
damn %>%
  anti_join(stop_words) %>%
  count(word, sort = TRUE) %>% 
  inner_join(get_sentiments("afinn")) %>% 
  inner_join(get_sentiments("bing")) %>% 
  filter(!word %in% c("tahm", "igh","kendrick", "lamar", "verse", "chorus", "1", "2")) %>% 
  head(20) %>%
  knitr::kable() -> damnsentiment
## Joining, by = "word"
## Joining, by = "word"
## Joining, by = "word"

The word count is 9060. Excluding the word “hol’” referring to the phrase “hol’ up” so I will be excluding it since it is not really a word. The most popular words are “feel”, “bitch”, and “love”. “Love” is not shocking since we have seen a theme of this word in his other albums. DAMN. is an “autobiographical parable in which he illustrates how his own destiny, that of the ‘greatest rapper,’” according to https://www.npr.org/2017/12/12/568748405/the-prophetic-struggle-of-kendrick-lamars-damn#:~:text=on%20%22XXX.%22-,DAMN.,tragic%20fate%20for%20all%20three.

Lets look at the sentiment of these words.

damnsentiment
word n value sentiment
bitch 48 -5 negative
love 45 3 positive
loyalty 38 3 positive
die 27 -3 negative
fear 26 -2 negative
shit 26 -4 negative
fuck 20 -4 negative
damn 14 -4 negative
hard 9 -1 negative
perfect 9 3 positive
sexy 9 3 positive
kill 8 -3 negative
killed 8 -3 negative
lost 8 -3 negative
trust 7 1 positive
bad 6 -3 negative
lovely 6 3 positive
murder 6 -2 negative
loyal 5 3 positive
worth 5 2 positive

This album is predominantly a negative album from the sentiment. Most of the words on the album have a low sentiment value because he claims the album is a “judgement of the soul.” The album consists of a song that narrates his own shooting death at the hands of a blind assailant. In his pre-album single, he proclaimed he was the “greatest rapper alive” and DAMN. solidified that according to https://www.npr.org/2017/04/17/524351436/kendrick-lamars-damn-is-introspective-and-unforgiving. With this knowledge, you would think that there would be a positive sentiment on the whole album but there is not. However, the same source says, DAMN. is a depressing album at times, as it can be quite evident that Kendrick has little to no hope left in him. The fire within him to fight against social injustice heard on To Pimp a Butterfly is seemingly replaced with a depressing realization that maybe these injustices are self-inflicted or unsolvable.

Spotify API for DAMN.

Let’s look at the danceability.

kendricklamar %>% 
  filter(album_name %in% "DAMN.")-> damnalbum

kendricklamar %>% 
  filter(album_name %in% "DAMN.") %>% 
  select(danceability, album_name, energy, track_name) %>% 
  kable()
danceability album_name energy track_name
0.357 DAMN. 0.238 BLOOD.
0.638 DAMN. 0.523 DNA.
0.670 DAMN. 0.700 YAH.
0.748 DAMN. 0.705 ELEMENT.
0.746 DAMN. 0.798 FEEL.
0.658 DAMN. 0.535 LOYALTY. FEAT. RIHANNA.
0.665 DAMN. 0.535 PRIDE.
0.908 DAMN. 0.621 HUMBLE.
0.678 DAMN. 0.562 LUST.
0.800 DAMN. 0.585 LOVE. FEAT. ZACARI.
0.568 DAMN. 0.619 XXX. FEAT. U2.
0.588 DAMN. 0.479 FEAR.
0.706 DAMN. 0.557 GOD.
0.552 DAMN. 0.731 DUCKWORTH.
0.357 DAMN. 0.238 BLOOD.
0.640 DAMN. 0.497 DNA.
0.679 DAMN. 0.697 YAH.
0.731 DAMN. 0.682 ELEMENT.
0.770 DAMN. 0.801 FEEL.
0.679 DAMN. 0.540 LOYALTY.
0.674 DAMN. 0.534 PRIDE.
0.911 DAMN. 0.566 HUMBLE.
0.704 DAMN. 0.545 LUST.
0.800 DAMN. 0.585 LOVE.
0.568 DAMN. 0.617 XXX.
0.618 DAMN. 0.473 FEAR.
0.709 DAMN. 0.561 GOD.
0.549 DAMN. 0.728 DUCKWORTH.
0.357 DAMN. 0.238 BLOOD.
0.640 DAMN. 0.497 DNA.
0.679 DAMN. 0.697 YAH.
0.731 DAMN. 0.682 ELEMENT.
0.770 DAMN. 0.801 FEEL.
0.679 DAMN. 0.540 LOYALTY. FEAT. RIHANNA.
0.674 DAMN. 0.534 PRIDE.
0.911 DAMN. 0.566 HUMBLE.
0.704 DAMN. 0.545 LUST.
0.800 DAMN. 0.585 LOVE. FEAT. ZACARI.
0.568 DAMN. 0.617 XXX. FEAT. U2.
0.618 DAMN. 0.473 FEAR.
0.709 DAMN. 0.561 GOD.
0.549 DAMN. 0.728 DUCKWORTH.
damnalbum %>%
  arrange(desc(danceability))%>%
  ggplot(aes(track_name, danceability, fill= track_name)) + geom_col() +
  theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust=1),legend.position = "none") + 
  coord_flip()+
   ggtitle("Danceability of Kendrick Lamar's Album, DAMN.")

This albums danceability is quite varied but is mostly relatively high. “HUMBLE” has the highest danceability rate which is the makes sense since it is a very upbeat song. “LOYALTY” has the lowest danceability rate. It is a song with more of a slower beat which gives it the lower danceability rate. His other album “To Pimp A Butterfly” has lower danceability which is interesting to see that “DAMN.” is somewhat higher.

Now lets look at valence.

damnalbum %>%
  filter(album_name %in% "DAMN.") %>%
  ggplot(aes(reorder(track_name, valence), valence) ) + geom_col() +
  coord_flip() +
  theme_economist()+
   ggtitle("Valence of Kendrick Lamar's Album, DAMN.")

The valence from this album is very high compared to other albums. Most of these songs are very happy but “LOYALTY.” is seen to have a low valence similar to danceability, because it is a song that is about unconditional love, which this song has a slower tempo. It is interesting to see that a song about love has such a low valence and is seen as depressing.

Finally I will compare all 4 of Lamar’s albums valence

lamar <- get_artist_audio_features('Kendrick Lamar')
lamar %>%  
  group_by(album_name) %>% 
  filter(!album_name %in% c("DAMN. COLLECTORS EDITION.", "To Pimp a Butterfly", "good kid, m.A.A.d city", "untitledunmastered.")) -> lamar_music
lamar_music %>% 
 filter(!album_name %in% c("Overly Dedicated", "Section.80", "Black Panther The Album Music From And Inspired By")) %>% 
  ggplot(aes(valence, album_name, fill = ..x..)) +
  geom_density_ridges_gradient() +
  theme_fivethirtyeight() + 
  xlim(0,1) +
  theme(legend.position = "none") +
  ggtitle("Valence of Kendrick Lamar's Albums")
## Picking joint bandwidth of 0.0745

Looking at the valence over time of each track, two of the albums, To Pimp A Butterfly and DAMN. start off depressing then get a lot happier then go back to depressing. These two albums both have an increase to happiness then a decrease down to sadder tunes. good kid, m.A.A.d city and Untitled Unmastered. both start off a little higher on the valence scale and have ups and downs of upbeat songs to more sad and depressing songs.

Conclusion

After doing extensive research on Kendrick Lamar’s discography, it is interesting to see that all four of his albums all had negative sentiments. From research, I had found that in his most recent album, “DAMN.” “Kendrick is defeated on this album. He has been beaten down and is left with a tangible feeling of despair. He has been looking for answers all this time and, after all of it, he is left thinking that maybe it’s his own fault. He is truly defeated by coming to the realization that he is the cause of his own torment and anguish.” I was not able to prove my hypothesis due to all of his albums being negative. Lamar seems to be struggling with self-love throughout his career which I think adds to the negative sentiment within his albums as well as focusing on themes like racism, oppression, and politics. The danceability of his two albums To Pimp a Butterfly and DAMN. are both relatively high, especially for rap, which I was suprised to see, but some of his songs do have low danceability rates like “LOYALTY.” and “XXX.” His two albums, good kid, m.A.A.d city and Untitled Unmastered. both have pretty high energy rates with a couple songs with lower energy rates. With rap music, it is most likely common to see high energy rates due to the fact that rap music typically ‘hypes’ people up and boosts listeners energy. The valence graphs overall we’re interesting to see but in the end of each album, the sound was gloomy and not uplifting like it is in the middle of his albums. Overall, it is clear to see that the energy rates and danceability give conflicting feelings from the sentiment analysis that was given for each album. Lyrically, the albums are more depressing due to the topics Lamar chooses to write about. But through danceability and energy, we are able to see that the music and beats he uses are uplifting to listeners. The valence graphs shows a mixture between happiness and gloominess of how his albums. They are parts that are positive and parts that are negative in each album. Lamar will be releasing an album on May 13, 2022 and it will be interesting to see if these themes will follow in his next album.

Below is a video of Evolution of Lamar from 2004-2017

embed_youtube("https://www.youtube.com/watch?v=DX3ClKYe4Wo")