Setup

knitr::opts_chunk$set(echo = FALSE)
library(readr)
library(ggplot2)
library(dplyr)
## 
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
## 
##     filter, lag
## The following objects are masked from 'package:base':
## 
##     intersect, setdiff, setequal, union
library(plotly)
## 
## Attaching package: 'plotly'
## The following object is masked from 'package:ggplot2':
## 
##     last_plot
## The following object is masked from 'package:stats':
## 
##     filter
## The following object is masked from 'package:graphics':
## 
##     layout
library(plotrix)

Spotify read.csv

spotify = read.csv("spotify_churn_dataset.csv")

Spotify!!!

Spotify! One of the top platforms for people to listen to their favorite songs, podcast, or even audio books. This data-set from Kaggle includes age ranges, what type of subscription (free, premium, etc.), gender, country, listening time, device used, ads listened to, and the churn factor.

This data-set is called a spotify_churn. Churn in terms of business is the cycle of subscribers. This helps identify factors in who leaves subscriptions and their data within it.

I am curious about the age ranges and the types of subscriptions people in those age ranges have.

Let’s have a look at a summary of this data-set.

Summary

summary(spotify)
##     user_id        gender               age          country         
##  Min.   :   1   Length:8000        Min.   :16.00   Length:8000       
##  1st Qu.:2001   Class :character   1st Qu.:26.00   Class :character  
##  Median :4000   Mode  :character   Median :38.00   Mode  :character  
##  Mean   :4000                      Mean   :37.66                     
##  3rd Qu.:6000                      3rd Qu.:49.00                     
##  Max.   :8000                      Max.   :59.00                     
##  subscription_type  listening_time  songs_played_per_day   skip_rate     
##  Length:8000        Min.   : 10.0   Min.   : 1.00        Min.   :0.0000  
##  Class :character   1st Qu.: 81.0   1st Qu.:25.00        1st Qu.:0.1500  
##  Mode  :character   Median :154.0   Median :50.00        Median :0.3000  
##                     Mean   :154.1   Mean   :50.13        Mean   :0.3001  
##                     3rd Qu.:227.0   3rd Qu.:75.00        3rd Qu.:0.4500  
##                     Max.   :299.0   Max.   :99.00        Max.   :0.6000  
##  device_type        ads_listened_per_week offline_listening   is_churned    
##  Length:8000        Min.   : 0.000        Min.   :0.0000    Min.   :0.0000  
##  Class :character   1st Qu.: 0.000        1st Qu.:0.0000    1st Qu.:0.0000  
##  Mode  :character   Median : 0.000        Median :1.0000    Median :0.0000  
##                     Mean   : 6.944        Mean   :0.7478    Mean   :0.2589  
##                     3rd Qu.: 5.000        3rd Qu.:1.0000    3rd Qu.:1.0000  
##                     Max.   :49.000        Max.   :1.0000    Max.   :1.0000

Let’s plot the Age range

ggplot(spotify, aes(x=age)) + geom_bar(fill= "lightblue") +
  labs(title = "Age of users of Spotify", x = "Age", y = "Count") + theme_minimal()

Age plus Subscription Type

xax <- list(title = "Subscription Type", 
    titlefont = list(family = "Verdana"))
yax <- list(title = "Age",               
    titlefont = list(family = "Verdana"))

agesub = plot_ly(
  data  = spotify,
  x = ~subscription_type,
  y = ~age,
  type = "box",
  color = ~subscription_type ) %>%
  layout(xaxis = xax, yaxis = yax, showlegend = TRUE)

Plotly of Age and Subscription

Subscription plus Churn

xax <- list(title = "Subscription", 
            titlefont = list(family = "Verdana"))
yax <- list(title = "Users",          
            titlefont = list(family = "Verdana"))
df <- as.data.frame(table(spotify$subscription_type, spotify$is_churned))
names(df) <- c("subscription_type", "is_churned", "n")

churn_sub = plot_ly(
    data = df,
    x = ~factor(subscription_type),
    y = ~n,
    color = ~factor(is_churned),
    type = "bar"
  ) %>%
  layout(barmode = "stack", xaxis = xax, yaxis = yax)

Plotly bar of Churn and Subscription Type

Interpreting the plots

So, we can see 0 means they have not churned and 1 means they churned. There are more users that have retained their subscription which is good for the business. It also is good to see that the premium subscription is the highest!

\(Student: {513\over1446}=0.35477\hspace{6.9cm}\) \(Premium: {530\over1585}=0.33438\hspace{6.9cm}\) \(Free: {503\over1515}=0.33201\hspace{6.9cm}\) \(Family: {525\over1383}=0.37961\hspace{6.9cm}\) \(Student: {513\over1959}=0.26187\hspace{6.9cm}\) \(Premium: {530\over2115}=0.25059\hspace{6.9cm}\) \(Free: {503\over2018}=0.24926\hspace{6.9cm}\) \(Family: {525\over1908}=0.275157\)

Listening time and Subscription type

listen_sub = ggplot(spotify, aes (x = listening_time, 
      fill = factor( subscription_type,
      levels=c("Free","Premium","Student", "Family")))) + 
  geom_histogram(position= "identity",bins = 30, 
                 color = "white") +
        labs(title = "Listening Time", fill = "Subscription",
             x = "Time", y = "Count") +
        scale_fill_brewer(palette="Pastel1")

GGplot histogram of Listening Time and Subscription Type

Pie chart for Subscription

counts = table(spotify$subscription_type)
pct = round(100 * counts/sum(counts), 1)
lbls = paste(names(counts), " (",counts, ", ", pct, "%)")

pie3D(counts, labels = lbls,explode = 0.05, 
      col = rainbow(length(counts)), labelcex = 0.9, 
      main = "Subscription Type")

Age and Churn QQ plot data

age_0 = spotify$age[spotify$is_churned==0]
age_1 = spotify$age[spotify$is_churned==1]
churnage = qqplot(age_0, age_1, xlab = "Retained", ylab = "Churned", main = "Retained vs Churned by Age")
abline(0,1, col = rgb(1,0,1), lwd=2)

Reflection

There are so many different plots we can use to see this data! Some are more useful than others. Now let’s figure out some problems…

What is the churn rate for spotify? Based on the plots there seems to be more people retained than churned so that’s great for spotify!

Let’s see one final plot just to be sure…

Final plot

Conclusion

Spotify seems to be doing great! Retaining users, including myself.

Thank you, keep on listening!!!