data(cars)
library(jsonlite)


url <- "https://min-api.cryptocompare.com/data/v2/histoday?fsym=BTC&tsym=USD&limit=100"

btc_data <- fromJSON(url)

btc_df <- btc_data$Data$Data

max_close <- max(btc_df$close, na.rm = TRUE)

max_close
## [1] 124723

Music and Popularity

1 How do the characteristics of music influence its popularity?

library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.1     ✔ stringr   1.5.2
## ✔ ggplot2   4.0.0     ✔ tibble    3.3.0
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.1.0     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter()  masks stats::filter()
## ✖ purrr::flatten() masks jsonlite::flatten()
## ✖ dplyr::lag()     masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
library(lubridate)
library(reshape2)
## 
## Attaching package: 'reshape2'
## 
## The following object is masked from 'package:tidyr':
## 
##     smiths
library(broom)

spotify <- read_csv("SpotifyFeatures.csv", show_col_types = FALSE)

spotify_clean <- spotify %>%
  rename(artists = artist_name) %>%
  mutate(
    year = if ("year" %in% colnames(.)) year else NA_real_,
    decade = floor(year / 10) * 10
  ) %>%
  select(track_name, artists, genre, popularity, danceability, energy, valence,
         loudness, tempo, acousticness, year, decade) %>%
  filter(!is.na(popularity))

model <- lm(popularity ~ danceability + energy + valence + loudness + tempo + acousticness,
            data = spotify_clean)

coeff_summary <- broom::tidy(model) %>%
  filter(term != "(Intercept)") %>%
  mutate(term = recode(term,
                       danceability = "Danceability",
                       energy = "Energy",
                       valence = "Valence (Happiness)",
                       loudness = "Loudness",
                       tempo = "Tempo (BPM)",
                       acousticness = "Acousticness"))

ggplot(coeff_summary, aes(x = reorder(term, estimate), y = estimate, fill = estimate > 0)) +
  geom_col() +
  coord_flip() +
  scale_fill_manual(values = c("TRUE" = "seagreen3", "FALSE" = "tomato")) +
  labs(title = "Influence of Song Characteristics on Popularity",
       x = "Song Feature",
       y = "Effect Size (Regression Coefficient)") +
  theme_minimal() +
  theme(legend.position = "none")

According to the graph, the characteristics of music that positively influence its popularity are danceability and loudness. Tempo (BPM) is neutral. The valence (happiness), energy, and acousticness had negative influences on the popularity of music.