Background

Hello, welcome to my Rmd!
I’ll be using Netflixglobal.csv data in this LBB
Let’s dig deeper into the data and name the object netflix!

Import Data

First, we can input the data

netflix <- read.csv("datainput/Netflixglobal.csv")

Data Inspection

library(tidyverse)
library(lubridate)

Then, using the functions head() and tail(), we will see the top data and the last data

head(netflix)
tail(netflix)

Check dimension data:

dim(netflix)
#> [1] 1160    7

Check category in Netflix :

unique(netflix$category)
#> [1] "Films (English)"     "Films (Non-English)" "TV (English)"       
#> [4] "TV (Non-English)"

From the inspection of the data, we can conclude:
* Netflix data contain 1160 of rows and 7 of coloumn
* Category Netflix of the data : “Films (English)”,“Films (Non-English)”,“TV (English)”,” TV (Non-English)

Data Cleansing

Check data types:

str(netflix)
#> 'data.frame':    1160 obs. of  7 variables:
#>  $ week                      : chr  "2022-01-16" "2022-01-16" "2022-01-16" "2022-01-16" ...
#>  $ category                  : chr  "Films (English)" "Films (English)" "Films (English)" "Films (English)" ...
#>  $ weekly_rank               : int  1 2 3 4 5 6 7 8 9 10 ...
#>  $ show_title                : chr  "Brazen" "Don't Look Up" "Mother/Android" "The Secret Life of Pets 2" ...
#>  $ season_title              : chr  "" "" "" "" ...
#>  $ weekly_hours_viewed       : int  45340000 28390000 23170000 9390000 8790000 8710000 8710000 8470000 7860000 7000000 ...
#>  $ cumulative_weeks_in_top_10: int  1 4 2 1 3 10 6 1 1 1 ...

We can see that there are some data types that do not match.
Then we can change the data type first!

netflix$category <- as.factor(netflix$category)
netflix$week <- as.Date(netflix$week)

str(netflix)
#> 'data.frame':    1160 obs. of  7 variables:
#>  $ week                      : Date, format: "2022-01-16" "2022-01-16" ...
#>  $ category                  : Factor w/ 4 levels "Films (English)",..: 1 1 1 1 1 1 1 1 1 1 ...
#>  $ weekly_rank               : int  1 2 3 4 5 6 7 8 9 10 ...
#>  $ show_title                : chr  "Brazen" "Don't Look Up" "Mother/Android" "The Secret Life of Pets 2" ...
#>  $ season_title              : chr  "" "" "" "" ...
#>  $ weekly_hours_viewed       : int  45340000 28390000 23170000 9390000 8790000 8710000 8710000 8470000 7860000 7000000 ...
#>  $ cumulative_weeks_in_top_10: int  1 4 2 1 3 10 6 1 1 1 ...

The data types change was successful!
We can continue to look for missing values.

Check missing value :

anyNA(netflix)
#> [1] FALSE
colSums(is.na(netflix))
#>                       week                   category 
#>                          0                          0 
#>                weekly_rank                 show_title 
#>                          0                          0 
#>               season_title        weekly_hours_viewed 
#>                          0                          0 
#> cumulative_weeks_in_top_10 
#>                          0

Good! No missing value.

Data Pre-Processing

  1. Which category has the highest proportion of cumulative weeks in top 10 ?
top_ten <- netflix %>% 
  select (category, cumulative_weeks_in_top_10)
  
top_ten
  1. What is the average weekly viewers (mean viewed) for each category in 2022 ?
netflix$year <- (year(netflix$week))
head(netflix$year)
#> [1] 2022 2022 2022 2022 2022 2022
case1 <- netflix %>% 
  filter(year == 2022) %>% 
  group_by(category) %>% 
  summarise(mean_viewed = mean(weekly_hours_viewed)) %>% 
  ungroup() %>% 
  arrange(desc(mean_viewed))
case1
  1. Which of the films in the top three weekly rankings has the most average weekly views of more than 50,000,000 times watched ?
case2 <- netflix %>% 
  filter(category == "Films (English)" | category == "Films (Non-English)" , weekly_rank <= 3 , weekly_hours_viewed > 50000000) %>% 
  group_by(show_title) %>% 
  summarise(mean_viewed = mean(weekly_hours_viewed)) %>% 
  ungroup() %>% 
  arrange(desc(mean_viewed))
case2
  1. Which film has the most views of the TV series that are in the top three weekly rankings and have average weekly views of more than 100,000,000 times watched ?
case3 <- netflix %>% 
  filter(category == "TV (English)" | category == "TV (Non-English)" , weekly_rank <= 3 , weekly_hours_viewed > 100000000) %>% 
  group_by(show_title) %>% 
  summarise(mean_viewed = mean(weekly_hours_viewed)) %>% 
  ungroup() %>% 
  arrange(desc(mean_viewed))
case3
  1. Show trending on Netflix !
trending_channel <- netflix %>% 
  group_by(show_title) %>% 
  summarise(n_position = n()) %>%
  ungroup() %>% 
  filter(n_position >= 10) %>% 
  arrange(desc(n_position)) 
trending_channel

Visualization

library(ggplot2)
  1. Frequency of cumulative weeks in top 10
ggplot(data = top_ten, mapping = aes(x = category, y = cumulative_weeks_in_top_10, color = category)) +
  geom_boxplot()

Data Visualization :

plot_topten <- ggplot(data = top_ten, mapping = aes(x = category, y = cumulative_weeks_in_top_10)) +
  geom_boxplot()+
  geom_jitter(aes(size = cumulative_weeks_in_top_10, color = category))+
    labs(title = "Frequency of Cumulative Weeks in Top 10",
       x = "Category",
       y = NULL,
       fill = NULL)+
  scale_fill_brewer(palette = "Set2")
plot_topten

Insight : Based on data, it appears that TV (Non - English) has the highest frequency on Cumulative Weeks in Top 10.

  1. Average viewed of category
ggplot(case1, aes(x=category, y=mean_viewed)) + 
    geom_col(mapping = aes(fill = category), 
           position = "dodge")+
  labs(title = "Proportion of Mean Viewed on 2021",
       subtitle = "Mean Viewed per Category",
       x = "Category",
       y = NULL,
       fill = NULL)+
  scale_fill_brewer(palette = "Set3")

Insight : Based on data, TV (Non - English) has the highest average viewers in 2022.

  1. Trending Channel on Netflix
ggplot(data = trending_channel, mapping = aes(x = n_position, y = reorder(show_title, n_position))) +
  geom_segment(aes( x = 0, xend = n_position, yend = reorder(show_title, n_position)), color="black") +
  geom_point(color= "indianred3", size=3,fill=alpha("orange", 0.3), alpha=0.7, shape=21, stroke=2)+
  geom_text(aes(label = n_position), nudge_x = 2) +
  labs(x = "Frequency", y = NULL, title = "Trending Channel Netflix")+
  theme_minimal()

Insight : Based on data, Money Heist is the trending channel on the frequency of show tittles.

  1. Average Viewed of Film on Netflix
ggplot(data = case2, aes(x = mean_viewed, y = reorder(show_title, mean_viewed)))+ 
  geom_col(aes(fill = mean_viewed), show.legend = F)+
  scale_fill_gradient(low = "rosybrown1", high = "brown4")+
  geom_text(aes(label = mean_viewed), nudge_x = 5) +
  labs(y = "show title", x = NULL, title = "Average Viewed of Film on Netflix")+
  theme_minimal()

Insight : Based on data, film with the highest average viewers in the film category is Red Notice.

  1. Average Viewed of TV series on Netflix
ggplot(data = case3, aes(x = mean_viewed, y = reorder(show_title, mean_viewed)))+ 
  geom_col(aes(fill = mean_viewed), show.legend = F)+
  scale_fill_gradient(low = "rosybrown1", high = "brown4")+
  geom_text(aes(label = mean_viewed), nudge_x = 5) +
  labs(y = "show title", x = NULL, title = "Average Viewed of TV series on Netflix")+
  theme_minimal()

Insight : Based on data, the highest average viewers in the tv series category is Squid Game.