Load Required Libraries
# Install packages if not already installed
if (!require("tidyverse")) install.packages("tidyverse")
if (!require("knitr")) install.packages("knitr")
library(tidyverse)
library(knitr)
Load the Netflix Dataset
# Check if file exists
if (!file.exists("Netflix.csv")) {
stop("Error: Netflix.csv file not found!")
}
# Read the Netflix dataset
Netflix <- read.csv("Netflix.csv", stringsAsFactors = FALSE)
# Check if data was loaded
if (nrow(Netflix) == 0) {
stop("Error: Netflix.csv is empty!")
}
Find Top 6 Actors in TV Shows
# Finding the 6 actors that have the most appearances on TV show
top_tv_actors <- Netflix_Actor %>%
select(type, actor) %>%
filter(type == "TV Show") %>%
group_by(actor) %>%
count(sort = TRUE) %>%
ungroup() %>%
head(6)
# Display the results
top_tv_actors %>%
kable(col.names = c("Actor", "Number of TV Show Appearances"),
caption = "Top 6 Actors with Most Appearances in Netflix TV Shows")
Top 6 Actors with Most Appearances in Netflix TV
Shows
|
210 |
| Takahiro Sakurai |
18 |
| Yuki Kaji |
16 |
| Daisuke Ono |
14 |
| David Attenborough |
14 |
| Ashleigh Ball |
12 |
Visualize the Results
# Create a bar plot
ggplot(top_tv_actors, aes(x = reorder(actor, n), y = n)) +
geom_bar(stat = "identity", fill = "#E50914") +
coord_flip() +
labs(title = "Top 6 Actors with Most Appearances in Netflix TV Shows",
x = "Actor",
y = "Number of Appearances") +
theme_minimal() +
theme(plot.title = element_text(hjust = 0.5, face = "bold"),
panel.grid.major.y = element_blank())
