Task 1: Reflection

My question for this challenge was do Spotify charted songs differ from those on Apple/Deezer/Shazam in terms of musical features? I used a histogram to show the difference between each feature. Based on the graphs you can see that danceability, energy, valence, and liveness had the highest feature in Deezer. Accoutiness and speechiness was highest for Apple. Shazam had the highest feature in instrumentalness. These graphs help show which platform you deserire in a song based on feature of preference.

Task 2: Interactive plots

# Load packages
library(tidyverse)
library(plotly)

# Load data
spotify_data <- read_csv("Popular_Spotify_Songs.csv")

# Make chart indicator columns numeric
spotify_data <- spotify_data %>%
  mutate(across(starts_with("in_"), as.numeric))

# Rename audio feature columns 
spotify_data <- spotify_data %>%
  rename(
    danceability = `danceability_%`,
    energy = `energy_%`,
    valence = `valence_%`,
    acousticness = `acousticness_%`,
    instrumentalness = `instrumentalness_%`,
    liveness = `liveness_%`,
    speechiness = `speechiness_%`
  )

# Set platform names and audio features
platforms <- c("spotify", "apple", "deezer", "shazam")
features <- c("danceability", "energy", "valence", 
              "acousticness", "instrumentalness", 
              "liveness", "speechiness")

# Set colors for each feature
feature_colors <- c(
  "danceability" = "orange",
  "energy" = "red",
  "valence" = "purple",
  "acousticness" = "blue",
  "instrumentalness" = "green",
  "liveness" = "yellow",
  "speechiness" = "brown"
)

# Calculate average feature values for each platform
avg_data <- map_dfr(platforms, function(p) {
  chart_col <- paste0("in_", p, "_charts")
  spotify_data %>%
    filter(.data[[chart_col]] > 0) %>%
    summarise(across(all_of(features), mean, na.rm = TRUE)) %>%
    mutate(platform = str_to_title(p))
})

# Reshape to long format for plotting
long_data <- avg_data %>%
  pivot_longer(-platform, names_to = "feature", values_to = "value")

# Use the first feature as the default
first_feat <- features[1]
first_data <- filter(long_data, feature == first_feat)

# Create the interactive Plotly bar chart
plot_ly() %>%
  add_trace(
    data = first_data,
    x = ~platform,
    y = ~value,
    type = "bar",
    marker = list(color = feature_colors[[first_feat]])
  ) %>%
  layout(
    title = paste("Average", str_to_title(first_feat), "by Platform"),
    xaxis = list(title = "Platform"),
    yaxis = list(title = "Value"),
    updatemenus = list(
      list(
        buttons = lapply(features, function(f) {
          list(
            method = "update",
            label = f,
            args = list(
              list(
                y = list(filter(long_data, feature == f)$value),
                x = list(filter(long_data, feature == f)$platform),
                marker = list(color = feature_colors[[f]])
              ),
              list(title = paste("Average", str_to_title(f), "by Platform"))
            )
          )
        }),
        direction = "down",
        showactive = TRUE,
        x = 0.1,
        y = 1.15
      )
    )
  )

Do the following:

  1. Make a plot. Any kind of plot will do (though it might be easiest to work with geom_point()).

  2. Make the plot interactive with ggplotly().

  3. Make sure the hovering tooltip is more informative than the default.

Good luck and have fun!

Task 3:

Install the {flexdashboard} package and create a new R Markdown file in your project by going to File > New File… > R Markdown… > From Template > Flexdashboard.

Using the documentation for {flexdashboard} online, create a basic dashboard that shows a plot (static or interactive) in at least three chart areas. Play with the layout if you’re feeling brave.