Using plotnine Geoms
(billie >> ggplot(aes("energy", "valence")) + geom_point() )
(billie >> ggplot(aes("energy", "valence", label = "track_name")) + geom_label() )
(billie >> ggplot(aes("energy", "valence", label = "track_name")) + geom_text() )
(billie >> ggplot(aes("energy", "valence", label = "track_name")) + geom_text(nudge_y = .1) + geom_point() )
More on geom options
The options below let you change different arguments to
geom_text(). Try changing them and running the code, in order to get a readable plot. Then, answer the questions underneath the plot.
Below are three songs at different corners of the graph. Can you tell whether they have high or low energy? Valence? Which do you think has low energy and low valence?
Hammer to Fall
Crazy Little Thing Called Love
Love of My Life
This exercise is a case study on selecting extreme differences between two features, such as energy and acousticness.
At the end of the case study, you'll be prompted to add code!
Generally tracks with higher energy tend to be less acoustic, as shown in the plot below.
But notice that in the plot above, there's a point in the top right, that is high energy and high acousticness.
In order to find high energy and acousticness songs like this, I used the following code.
|23989||MC Kevin o Chris||Vamos pra Gaiola||Vamos pra Gaiola||0.971||0.521||0.872||0.2810||0.917000||61||161.600|
|5210||ScHoolboy Q||CrasH Talk||Black Folk||0.902||0.400||0.734||0.3960||0.831000||51||147.040|
|24928||MC Kevin o Chris||Eu Vou pro Baile da Gaiola||Eu Vou pro Baile da Gaiola||0.957||0.642||0.832||0.1050||0.824000||52||123.220|
|18950||Foo Fighters||There Is Nothing Left To Lose||Learn to Fly||0.919||0.537||0.465||0.0408||0.000018||74||235.293|
|20424||Foo Fighters||One By One (Expanded Edition)||Times Like These||0.908||0.265||0.377||0.0899||0.000014||68||265.560|
|21870||Turmion Kätilöt||Global Warning||Jumalauta||0.939||0.549||0.454||0.0618||0.000010||42||210.107|
812 rows × 10 columns
Can you plot songs by MC Kevin o Chris, with both points and text?
⚠️: Don't forget to replace all the blanks!
Why do you think Vamos pra Gaiola is high energy and high acousticness?
answerMy best guess is because the drums are done by a persons voice, there are few instruments, but it is still a pretty fast tempo. It would be interesting to look at their other tracks for a comparison.
Can you modify each code block in the case study to be about high energy and low danceability songs?