# Load necessary libraries
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(ggplot2)
## Warning: package 'ggplot2' was built under R version 4.3.3
library(tidyr)
library(readxl)

# Read the Netflix dataset from Excel file
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")

# View the first few rows of the dataset
View(netflix2)

# Check for missing values in each column
missing_values_count <- colSums(is.na(netflix2))
missing_values_count
##      show_id         type        title     director      country   date_added 
##            0            0            0            0            0            0 
## release_year       rating     duration    listed_in 
##            0            0            0            0
#2What is the  distribution of movies vs TV shows in dataset by bar graph?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
library(ggplot2)
ggplot(netflix2,aes(x = type))+
  geom_bar(fill = c("blue","red")) +
  labs(title="Distribution of Movies vs TV Shows" ,
       xlab="Content Type",
       ylab="Count")

#3In which year most movies and tv shows are releases?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
library(dplyr)
library(ggplot2)
movies_data = netflix2 %>% filter(type == "Movie")
tv_shows_data =netflix2 %>% filter(type == "TV Show")

movies_in_year = movies_data %>% 
  group_by(release_year) %>% 
  summarise(count = n()) %>% 
  arrange(desc(count)) %>% 
  head(1)

tv_shows_in_year= tv_shows_data %>% 
  group_by(release_year) %>% 
  summarise(count = n()) %>% 
  arrange(desc(count)) %>% 
  head(1) 

cat("Most Tv shows releases in year : ",tv_shows_in_year $release_year,"\n",
    "Most movies releases in year : ", movies_in_year$release_year)
## Most Tv shows releases in year :  2020 
##  Most movies releases in year :  2018
#4What are top 10 movies with highest rating?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
library(dplyr)
top_movies =netflix2 %>% 
  filter(type == "Movie") %>% 
  arrange(desc(movies_data)) %>% 
  select(title, rating) %>% 
  head(10)

top_movies
## # A tibble: 10 × 2
##    title                                           rating
##    <chr>                                           <chr> 
##  1 "Searching For Sheela"                          TV-14 
##  2 "HOMUNCULUS"                                    TV-MA 
##  3 "Vizontele"                                     TV-MA 
##  4 "This Lady Called Life"                         TV-14 
##  5 "Perfume Imaginary Museum “Time Warpâ€\u009d" TV-G  
##  6 "One Like It"                                   TV-G  
##  7 "Niyazi Gül Dörtnala"                         TV-MA 
##  8 "My Travel Buddy"                               TV-MA 
##  9 "Legal Hash"                                    TV-MA 
## 10 "Kocan Kadar Konus 2: Dirilis"                  TV-14
#5Top 10 countries have the most content on Netflix and show on bar graph?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
library(ggplot2)
country_count=netflix2 %>% group_by(country) %>%
                summarise(Count = n())
Top10=head(country_count, 10)

ggplot(Top10, aes(x = country, y = Count)) +
  geom_bar(stat = "identity", fill = "skyblue") +
  labs(title = "Top 10 Countries with Most Content on Netflix",
       x = "Country",
       y = "Number of Titles")

#6Create a bar chart to visualize the distribution of content ratings?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
library(ggplot2)
rating_counts= netflix2 %>%
  group_by(rating) %>%
  summarise(count = n()) %>%
  arrange(desc(count))

ggplot(rating_counts, aes(x= rating, y = count)) +
  geom_bar(stat = "identity", fill = "skyblue") +
  labs(title = "Distribution of content ratings on Netflix",
       x = "Content rating",
       y = "Number of titles")

#7visualize releases TV Shows over the years.
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
tv_shows_data =netflix2 %>% filter(type == "TV Shows")

ggplot(tv_shows_data, aes(x= release_year)) +
  geom_histogram(binwidth = 3, fill = "blue", color = "black") +
  labs(title = "Release year of TV Shows on netflix" ,
       x = "Release year",
       y = "Count")

#8visualize  releases movies over the years.
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
movies_data =netflix2 %>% filter(type == "Movie")

ggplot(movies_data, aes(x = release_year)) +
  geom_histogram(binwidth = 2, fill = "blue", color = "black") +
  labs(title = "Histogram of movie release year on netflix",
       x = "Release year",
       y = "Number of movies")

#9 visualize top 10 director with most released movies and TV shows?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
top_director= netflix2 %>%
  group_by(director) %>%
  summarise(count = n()) %>%
  arrange(desc(count)) %>% slice(-1) %>%
  head(10)  

ggplot(top_director, aes(x =director, y = count)) +
  geom_bar(stat = "identity", fill = c("red","blue","pink","skyblue","yellow",
                                       "purple","green","grey","orange","black")) +
  labs(title = "Top 10 directors with most content on Netflix",
       x = "Director",
       y = "Number of titles")

#10What number of movies and tv shows watch by Children & Family Movies, Comedies?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
Seen_by= netflix2 %>% filter(listed_in=="Children & Family Movies, Comedies")
total_no. = Seen_by %>%
  group_by(listed_in) %>%
  summarise(count=n()) 
total_no.
## # A tibble: 1 × 2
##   listed_in                          count
##   <chr>                              <int>
## 1 Children & Family Movies, Comedies   201
#11On which date most movies and Tv shows are released?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
release_date_year =netflix2 %>%
  group_by(date_added) %>%
  summarise(Count = n()) %>%
  arrange(desc(Count)) %>%
  head(1)
release_date_year
## # A tibble: 1 × 2
##   date_added Count
##   <chr>      <int>
## 1 43831        110
#12is there correlation between type and rating?? 
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
str(netflix2)
## tibble [8,790 × 10] (S3: tbl_df/tbl/data.frame)
##  $ show_id     : chr [1:8790] "s1" "s3" "s6" "s14" ...
##  $ type        : chr [1:8790] "Movie" "TV Show" "TV Show" "Movie" ...
##  $ title       : chr [1:8790] "Dick Johnson Is Dead" "Ganglands" "Midnight Mass" "Confessions of an Invisible Girl" ...
##  $ director    : chr [1:8790] "Kirsten Johnson" "Julien Leclercq" "Mike Flanagan" "Bruno Garotti" ...
##  $ country     : chr [1:8790] "United States" "France" "United States" "Brazil" ...
##  $ date_added  : chr [1:8790] "9/25/2021" "9/24/2021" "9/24/2021" "9/22/2021" ...
##  $ release_year: num [1:8790] 2020 2021 2021 2021 1993 ...
##  $ rating      : chr [1:8790] "PG-13" "TV-MA" "TV-MA" "TV-PG" ...
##  $ duration    : chr [1:8790] "90 min" "1 Season" "1 Season" "91 min" ...
##  $ listed_in   : chr [1:8790] "Documentaries" "Crime TV Shows, International TV Shows, TV Action & Adventure" "TV Dramas, TV Horror, TV Mysteries" "Children & Family Movies, Comedies" ...
#13 What number of movies are of Comedies?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
movies_data_1=netflix2 %>% filter(type == "Movie") 
   A= movies_data_1%>% filter(listed_in=="Comedies")
movie_number = A %>%
  group_by(listed_in) %>%
  summarise(count=n())
movie_number
## # A tibble: 1 × 2
##   listed_in count
##   <chr>     <int>
## 1 Comedies    110
#14 Visualize the borplot between type and release_year?
netflix2 <- read_excel("C:/Users/91904/Desktop/netflix2.xlsx")
ggplot(netflix2, aes(x = type, y = release_year, color = type)) +
  geom_boxplot()+
  labs(x = "Type", y = "Release Year")