Rmarkdown


  1. Create a new .Rmd file. Choose the HTML file type.

  1. Modify the YAML header specifying:

  1. Modify the YAML to include a table of contents and knit the document.

  1. Specify in the YAML that you want a floating table of contents and knit the document.

  1. Insert a code chunk to read the dataset spotify_weekly_chart (downloaded from @Kaggle) from the Dataset folder. Then:

    • Give a name to this code chunk.

    • Add plain text description above the code chunk:

      “The dataset contains data regarding the artist and the songs on the Spotify global weekly chart.
      For each song, the artist name, the number of stream and the peak in the chart are reported.”

    • Add the following unordered list describing the variables:

      • Pos : position of the song in the chart
      • P. : number of position gained since last week
      • Artist : name of the artist
      • Title : title of the song
      • Wks : number of weeks spent on the chart
      • Pk: peak position of the song
      • X.x..: number of times the peak position has been attained
      • Streams : number of streams of the song
      • Streams. : number of streams gained or lost since last week
      • Total : total number of streams
kaggle_spotify_weekly_chart <- read.csv("Exercises/Datasets/spotify_weekly_chart.csv")
head(kaggle_spotify_weekly_chart)
##   Pos P.         Artist           Title Wks Pk X.x..  Streams Streams.
## 1   1  =           SZA        Kill Bill   5  1  (x2) 47288509  5814143
## 2   2 +3  Metro Boomin         Creepin'   6  2  (x1) 30753658  2661426
## 3   3 -1     Sam Smith           Unholy  16  1  (x7) 30733283 -2398892
## 4   4 -1  Harry Styles        As It Was  41  1 (x11) 28522200 -2475884
## 5   5 -1  David Guetta  I'm Good (Blue)  20  2  (x4) 27260313 -3443943
## 6   6  = Manuel Turizo       La Bachata  28  4       25879286 -1477809
##        Total
## 1  208044297
## 2  184223144
## 3  673533882
## 4 1747957886
## 5  568898155
## 6  693820743

  1. Add a code chunk in the Data transformation section to:
dim(kaggle_spotify_weekly_chart)
## [1] 200  10
artists <- kaggle_spotify_weekly_chart[1:5, 'Streams']
names(artists) <- kaggle_spotify_weekly_chart[1:5,'Artist']

songs <- kaggle_spotify_weekly_chart[1:5, 'Streams']
names(songs) <- kaggle_spotify_weekly_chart[1:5, 'Title']

  1. Add a code chunk to produce a barplot representing the streams of the top five artists in the chart. Do you need to specify names? Why?
barplot(height  = artists, 
        main = 'Spotify streams of top 5 artists of the week chart'
        ) 


  1. Add a code chunk to produce a barplot representing the streams of the top five songs in the chart.
barplot(height  = songs, 
        main = 'Spotify streams of top 5 songs of the week chart')


  1. Add a “Conclusions” section to insert a plain text listing the titles of the top 5 songs in the chart.

  1. Create a new R Markdown file for exercises on plots done on 10/03/2025.
    Modify dimensions and parameters on the plots to achieve the best possible visualization and improve aestahetics.