1 Overview

Halo, Berikut adalah Rmd yang saya buat sebagai tugas LBB Algoritma Data Science. Kali ini saya menggunakan dataset dari file USvideos.csv yang ada pada materi Data Visualization. Dataset ini berisi informasi video trending youtube US pada tahun 2017. Saya akan mencoba menggali beberapa insight dari data tsb dan memvisualisasikannya kedalam bentuk plot

2 Pre-Processing

Yang pertama, saya akan membaca dataset tersebut untuk dimasukkan kedalam dataframe menggunakan fungsi read.csv

df_youtube <- read.csv("data_input/USvideos.csv")
str(df_youtube)
## 'data.frame':    13400 obs. of  12 variables:
##  $ trending_date         : chr  "17.14.11" "17.14.11" "17.14.11" "17.14.11" ...
##  $ title                 : chr  "WE WANT TO TALK ABOUT OUR MARRIAGE" "The Trump Presidency: Last Week Tonight with John Oliver (HBO)" "Racist Superman | Rudy Mancuso, King Bach & Lele Pons" "Nickelback Lyrics: Real or Fake?" ...
##  $ channel_title         : chr  "CaseyNeistat" "LastWeekTonight" "Rudy Mancuso" "Good Mythical Morning" ...
##  $ category_id           : int  22 24 23 24 24 28 24 28 1 25 ...
##  $ publish_time          : chr  "2017-11-13T17:13:01.000Z" "2017-11-13T07:30:00.000Z" "2017-11-12T19:05:24.000Z" "2017-11-13T11:00:04.000Z" ...
##  $ views                 : int  748374 2418783 3191434 343168 2095731 119180 2103417 817732 826059 256426 ...
##  $ likes                 : int  57527 97185 146033 10172 132235 9763 15993 23663 3543 12654 ...
##  $ dislikes              : int  2966 6146 5339 666 1989 511 2445 778 119 1363 ...
##  $ comment_count         : int  15954 12703 8181 2146 17518 1434 1970 3432 340 2368 ...
##  $ comments_disabled     : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
##  $ ratings_disabled      : logi  FALSE FALSE FALSE FALSE FALSE FALSE ...
##  $ video_error_or_removed: logi  FALSE FALSE FALSE FALSE FALSE FALSE ...

Data tersebut berisi kolom-kolom dengan deskripsi :

  • trending_date: tanggal trending
  • title: judul video
  • channel_title: nama channel Youtube
  • category_id: kategori video
  • publish_time: tanggal upload video
  • views: jumlah views
  • likes: jumlah likes
  • dislikes: jumlah dislikes
  • comment_count: jumlah komentar
  • comment_disabled: apakah kolom komentar tidak diaktifkan
  • rating_disabled: apakah rating video tidak diaktifkan
  • video_error_or_removed: apakah video dihapus

Lalu merubah tipe data pada kolom yang masih belum sesuai. Kolom yang akan dirubah adalah : - trending_date, dari karakter menjadi date - category_id, dari integer menjadi kategori dengan cara mapping id kategori dengan deskripsi kategorinya. - publish_time, dari karakter menjadi datetime

Kemudian pastikan supaya tidak ada missing value dalam dataframe, bisa menggunakan fungsi summary

summary(df_youtube)
##  trending_date           title           channel_title      category_id       
##  Min.   :2017-11-14   Length:13400       Length:13400       Length:13400      
##  1st Qu.:2017-11-30   Class :character   Class :character   Class :character  
##  Median :2017-12-17   Mode  :character   Mode  :character   Mode  :character  
##  Mean   :2017-12-17                                                           
##  3rd Qu.:2018-01-03                                                           
##  Max.   :2018-01-21                                                           
##   publish_time                     views               likes        
##  Min.   :2008-04-05 18:22:40   Min.   :      687   Min.   :      0  
##  1st Qu.:2017-11-25 20:52:30   1st Qu.:    91096   1st Qu.:   1987  
##  Median :2017-12-13 02:23:04   Median :   309796   Median :   8907  
##  Mean   :2017-11-18 18:46:37   Mean   :  1234583   Mean   :  45662  
##  3rd Qu.:2017-12-27 14:00:03   3rd Qu.:   996668   3rd Qu.:  29376  
##  Max.   :2018-01-21 05:44:30   Max.   :149376127   Max.   :3093544  
##     dislikes       comment_count       comments_disabled ratings_disabled
##  Min.   :      0   Min.   :      0.0   Mode :logical     Mode :logical   
##  1st Qu.:     85   1st Qu.:    283.8   FALSE:13172       FALSE:13341     
##  Median :    322   Median :   1017.5   TRUE :228         TRUE :59        
##  Mean   :   3352   Mean   :   5982.4                                     
##  3rd Qu.:   1113   3rd Qu.:   3362.2                                     
##  Max.   :1674420   Max.   :1361580.0                                     
##  video_error_or_removed
##  Mode :logical         
##  FALSE:13399           
##  TRUE :1               
##                        
##                        
## 

Jika diperhatikan, data masih berisi informasi video yang trending setiap harinya sehingga satu judul dapat muncul berulang kali dengan jumlah views yang semakin bertambah. Kita hanya memerlukan informasi kapan sebuah video trending sehingga akan diambil 1 data saja yang pertama kali muncul dengan fungsi match dan unique.

vids.unik <- df_youtube[ match(x = unique(df_youtube$title), table = df_youtube$title), ]

3 Data Wrangling

Karena data sudah bersih, tahap selanjutnya Data Wrangling. Kita akan tentukan dulu beberapa business questionnya untuk digali yaitu :

  • Top 10 channel yang videonya paling sering trending
vids_agg <- aggregate(title ~ channel_title, vids.unik, length)
vids_10 <- head(vids_agg[order (-vids_agg$title),],10)
vids_10
##                               channel_title title
## 1019                             Refinery29    31
## 1226 The Tonight Show Starring Jimmy Fallon    30
## 1354                                    Vox    29
## 1241                           TheEllenShow    28
## 881                                 Netflix    27
## 889                                     NFL    25
## 390                                    ESPN    24
## 607                       Jimmy Kimmel Live    24
## 1200     The Late Show with Stephen Colbert    22
## 683             Late Night with Seth Meyers    21
  • Kategori video yang paling banyak ditonton
vids_vw <- aggregate(views ~ category_id, vids.unik, sum)
vids_5 <- head(vids_vw[order(-vids_vw$views),],5)
vids_5
##          category_id     views
## 4      Entertainment 445350694
## 8              Music 386197869
## 2             Comedy 179900099
## 7    Howto and Style 110259469
## 5 Film and Animation  77476128
  • Pola hubungan views dari comment_per_view dan likes_per_view untuk kategori channel yang paling banyak ditonton
vids_subset <- vids.unik[vids.unik$category_id %in% c("Entertainment","Music","Comedy","Howto and Style","Film and Animation"),]
vids_subset$like_per_view <- round(vids_subset$likes/vids_subset$views,3)
vids_subset$comment_per_view <- round(vids_subset$comment_count/vids_subset$views,3)

4 Data Visualization

Sampai di tahap terakhir, dimana data yang sudah diperoleh dari proses wrangling sebelumnya akan divisualisasikan kedalam ggplot

options(scipen = 999)
library(tidyverse)

vids_10 %>%
  ggplot(aes(x=reorder(channel_title,title), y=title, fill = channel_title) ) +
    geom_bar(stat="identity",show.legend = FALSE) +
    coord_flip() +
  labs( x="Channel Title",
        y="Trending Videos",
    title = "US Trending Videos",
    subtitle = "Top 10 Channels With Most Trending Videos"
  ) +
    theme(
    plot.title = element_text(color = "#696969", size = 16),
    plot.subtitle = element_text(face = "italic")
  )

vids_5 %>%
  ggplot(aes(x=reorder(category_id,-views), y=views, fill=category_id ) ) +
    geom_col(stat="identity",show.legend = FALSE) +
  geom_text(aes(label = format(views, big.mark = ",",
                               scientific = FALSE) ),
            vjust = -0.5,
            size = 3,
            colour = "Red")+
  scale_y_continuous(labels = scales::comma)+
  labs( x="Category",
        y="Views",
    title = "US Trending Videos",
    subtitle = "Top 5 Most Watched Video Categories"
  ) +
    theme(
    plot.title = element_text(color = "#696969", size = 16),
    plot.subtitle = element_text(face = "italic")
  )

library(hrbrthemes)

ggplot(vids_subset, aes(x=comment_per_view, y=like_per_view, color=category_id)) + 
    geom_point(size=2) +
    theme_ipsum()+
  labs(x="comment per view",
       y="like per view",
       title = "US Trending Videos",
    subtitle = "Comment per View and Like per View from Most Viewed Video Categories") +
  theme(
    plot.title = element_text(color = "#696969", size = 16),
    plot.subtitle = element_text(face = "italic", size =10)
  )