Using data on credit card applicationsâ status please present the frequency table with the nice, kable format for average monthly credit card expenditures of applicants.
data(CreditCard)
CreditCard <- CreditCard %>% filter(months!=0) %>% filter(card == "yes")%>% mutate(monthly_expenditure = expenditure / months)
tabela4<-Freq(CreditCard$monthly_expenditure,useNA="ifany")
#using frequency_df to make sure that every second column/row will look diffrently
frequency_df <- as.data.frame(tabela4)
tabela4 %>%
kable(col.names = c("Avg Mon_Exp in kUSD ","Frequency ","Percentage % ","Cumulative frequency ","Cumulative percentage % ")) %>%
kable_styling(bootstrap_options = "bordered") %>%
column_spec(seq(1, ncol(frequency_df), by = 2), italic = T, background = "lightgray") %>%
row_spec(seq(1, nrow(frequency_df), by = 2), italic = T, bold = TRUE, background = "darkgray")
| Avg Mon_Exp in kUSD | Frequency | Percentage % | Cumulative frequency | Cumulative percentage % |
|---|---|---|---|---|
| [0,50] | 937 | 0.9168297 | 937 | 0.9168297 |
| (50,100] | 44 | 0.0430528 | 981 | 0.9598826 |
| (100,150] | 14 | 0.0136986 | 995 | 0.9735812 |
| (150,200] | 12 | 0.0117417 | 1007 | 0.9853229 |
| (200,250] | 8 | 0.0078278 | 1015 | 0.9931507 |
| (250,300] | 1 | 0.0009785 | 1016 | 0.9941292 |
| (300,350] | 0 | 0.0000000 | 1016 | 0.9941292 |
| (350,400] | 1 | 0.0009785 | 1017 | 0.9951076 |
| (400,450] | 1 | 0.0009785 | 1018 | 0.9960861 |
| (450,500] | 4 | 0.0039139 | 1022 | 1.0000000 |
The data comes from https://flixgem.com/ (dataset version as of March 12, 2021). The data contains information on 9425 movies and series available on Netlix.
Answer with the most appropriate data visualization for the following questions:
1.What is the distribution of Imdb scores for Polish movies and movie-series?
#Reading the database
netflix_data <- read.csv("https://raw.githubusercontent.com/kflisikowski/ds/master/netflix-dataset.csv")
polish <- netflix_data[netflix_data$Languages == "Polish", ]
# Distribution of IMDb scores for Polish movies and movie-series
ggplot(polish) +
geom_histogram(aes(x = IMDb.Score), fill = "lightgreen", color = "black") +
scale_x_continuous(breaks = seq(0, 10, by = 0.5)) +
labs(title = "Distribution of IMDb Scores for Polish Movies and Movie-Series",
x = "IMDb Scores",
y = "Amount")
2.What is the density function of Imdb scores for Polish movies and movie-series?
# Filter Polish movies and series
polish_movies <- polish[polish$`Series.or.Movie` == "Movie", ]
polish_series <- polish[polish$`Series.or.Movie` == "Series", ]
# Plot density function separately for movies and series
ggplot() +
geom_density(data = polish_movies, aes(x = IMDb.Score, fill = "Movie"), alpha = 0.5) +
geom_density(data = polish_series, aes(x = IMDb.Score, fill = "Series"), alpha = 0.5) +
labs(title = "Density Function of IMDb Scores for Polish Movies and Series",
x = "IMDb Scores",
y = "Density") +
scale_fill_manual(values = c("darkred", "lightblue"), labels = c("Movie", "Series")) +
guides(fill = guide_legend(title = "Type"))
3.What are the most popular languages available on Netflix?
# Spliting the data, becouse there can be two or more languages
netflix_data <- netflix_data %>%
separate_rows(Languages, sep = ", ") %>%
filter(!is.na(Languages))
# Count occurences of each language
language_counts <- netflix_data %>%
group_by(Languages) %>%
summarize(count = n()) %>%
arrange(desc(count))
# Creating visual reprezentation
ggplot(language_counts[1:10, ], aes(x = reorder(Languages, -count), y = count)) +
geom_bar(stat = "identity", fill = "pink", color = "black") +
labs(title = "Top 10 Most Popular Languages on Netflix",
x = "Language",
y = "Count") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Create a chart showing actors starring in the most popular productions.
#top 25 film by IMDb.Votes
top_films <- netflix_data %>%
arrange(desc(`IMDb.Votes`)) %>%
head(25)
# Count occurences of each actor in the top films
actor_counts <- top_films %>%
filter(!is.na(Actors)) %>%
separate_rows(Actors, sep = ", ") %>%
group_by(Actors) %>%
summarize(count = n()) %>%
arrange(desc(count))
# create data visualization
ggplot(actor_counts[1:10, ], aes(x = reorder(Actors, -count), y = count)) +
geom_bar(stat = "identity", fill = "gold", color = "black") +
labs(title = "Top 10 Actors with most apparencess in 25 most popular productions",
x = "Actor",
y = "Count") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
For movies and series, create rating charts from the various portals (Hidden Gem, IMDb, Rotten Tomatoes, Metacritic). Hint: itâs a good idea to reshape the data to long format.
#resheping data in long format
ratings_long <- netflix_data %>%
select(-Title, -Languages, -Genre, -TMDb.Trailer, -Trailer.Site, -Poster, -Tags, -Country.Availability, -Runtime, -Director, -Writer, -Actors, -View.Rating, -Awards.Received, -Awards.Nominated.For, -Boxoffice, -Release.Date, -Netflix.Release.Date, -Production.House, -Netflix.Link, -IMDb.Link, -Summary, -IMDb.Votes, -Image) %>%
pivot_longer(cols = ends_with("Score"), names_to = "Portal", values_to = "Rating") %>%
mutate(Portal = gsub("Rating.", "", Portal),
Portal = gsub("\\.", " ", Portal)) %>% # Replace periods with spaces
group_by(`Series.or.Movie`, Portal) %>%
summarize(mean_rating = mean(Rating, na.rm = TRUE))
# Create data Visualization
ggplot(ratings_long, aes(x = Portal, y = mean_rating, color = `Series.or.Movie`, group = `Series.or.Movie`)) +
geom_line() +
labs(title = "Rating Charts from Various Portals for Movies and Series",
x = "Portal",
y = "Mean Rating") +
theme(axis.text.x = element_text(angle = 45, hjust = 1))
Which film studios produce the most and how has this changed over the years?
netflix_data$Release_Year <- as.integer(format(as.Date(netflix_data$`Release.Date`, format = "%m/%d/%Y"), "%Y"))
filtered_data <- netflix_data %>%
filter(Production.House != "")
# Group the data by film studio and year, count the number of movies
studio_year_counts <- filtered_data %>%
filter(!is.na(Release_Year)) %>% # Filter out rows with missing release year
group_by(`Production.House`, Release_Year) %>%
summarize(num_movies = n()) %>%
ungroup()
# Find the top film studios by total number of movies produced
top_studios <- studio_year_counts %>%
group_by(`Production.House`) %>%
summarize(total_movies = sum(num_movies)) %>%
top_n(10, total_movies) # Select top 10 studios
# Filter data for top film studios
top_studio_data <- studio_year_counts %>%
filter(`Production.House` %in% top_studios$`Production.House`)
# Creating data visaulization
ggplot(top_studio_data, aes(x = Release_Year, y = num_movies, color = `Production.House`)) +
geom_line() +
labs(title = "Trend of Movie Production by Top Film Studios Over the Years",
x = "Release Year",
y = "Number of Movies") +
theme(legend.position = "right", legend.title = element_blank())
The top studio
total_studio_movies <- studio_year_counts %>%
group_by(Production.House) %>%
summarize(total_movies = sum(num_movies)) %>%
arrange(desc(total_movies))
# Select the top studio
top_studio <- total_studio_movies$Production.House[1]
# Filter data for the top studio
top_studio_data <- studio_year_counts %>%
filter(Production.House == top_studio)
# Creating data visaulization
ggplot(top_studio_data, aes(x = Release_Year, y = num_movies)) +
geom_line(color = "purple", size = 1.5) + # Increase line thickness
labs(title = paste("Trend of Movie Production for", top_studio, "Over the Years"),
x = "Release Year",
y = "Number of Movies") +
scale_y_continuous(breaks = seq(0, max(top_studio_data$num_movies), by = 0.5))