from setup import ___
from siuba import *
from plotnine import *
from music_top200 import music_top200, track_features
Geoms
Click here to open the slides full screen.
Exercise 1:
The code below uses geom_text()
. Try changing options and then re-running the code, in order to get a readable plot. Then, answer the questions underneath the plot.
Options to set:
- Change
size = 11
tosize = 5
. Try out sizes 7 and 14. - Change horizontal align from
ha = "center"
toha = "left"
.- How about
"right"
?
- How about
- Change nudge from
nudge_y = 0
tonudge_y = .05
, ornudge_x = .05
.- What about
-.05
?
- What about
Code
(track_features>> filter(_.artist == "Queen")
>> ggplot(aes("energy", "valence", label = "track_name"))
+ geom_point()
+ geom_text(size = 11, ha = "center", nudge_y = 0)
)
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
Exercise 2:
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.
(track_features>> filter(_.popularity > 33)
>> ggplot(aes("energy", "acousticness"))
+ geom_point()
)
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.
(track_features>> filter(_.energy > .9, _.popularity > 33)
>> arrange(-_.acousticness)
)
artist | album | track_name | energy | valence | danceability | speechiness | acousticness | popularity | duration | |
---|---|---|---|---|---|---|---|---|---|---|
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?
(track_features>> filter(_.artist == "MC Kevin o Chris")
>> ___
)
Why do you think Vamos pra Gaiola is high energy and high acousticness?
answer
My 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?