library(magrittr)
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(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ forcats 1.0.0 ✔ readr 2.1.5
## ✔ ggplot2 3.5.0 ✔ stringr 1.5.1
## ✔ lubridate 1.9.3 ✔ tibble 3.2.1
## ✔ purrr 1.0.2 ✔ tidyr 1.3.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ tidyr::extract() masks magrittr::extract()
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ✖ purrr::set_names() masks magrittr::set_names()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data <- read.csv("CreditCard.csv")
netflix_data = read.csv("https://raw.githubusercontent.com/kflisikowski/ds/master/netflix-dataset.csv?raw=true")
Ex1 is the last one as table is super long and I don’t know if we
supposed to have so many months
Ex2 First
netflix_data %>%
filter(grepl("Poland", Country.Availability) & grepl("Polish", Languages)) %>%
ggplot(aes(x = IMDb.Score, fill = Series.or.Movie, alpha=0.5)) +
geom_histogram()
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.

Ex2 Second
netflix_data %>%
filter(grepl("Poland", Country.Availability) & grepl("Polish", Languages)) %>%
ggplot(aes(x = IMDb.Score, fill = Series.or.Movie, alpha=0.5)) +
geom_density()

Ex2 Third
popular_language <- netflix_data %>%
separate_rows(Languages, sep=", ") %>%
select(Title,Languages)
popular_language <- popular_language %>%
group_by(Languages) %>%
transmute(count = n()) %>%
distinct() %>%
arrange(desc(count)) %>%
head(12)
ggplot(popular_language,aes(x=Languages,y=count)) +
geom_col()

Challenge 1
knitr::include_graphics("Challenge 3.1.png")

Challenge 2
long_data <- netflix_data %>%
select(Series.or.Movie,Hidden.Gem.Score,IMDb.Score,Rotten.Tomatoes.Score,Metacritic.Score) %>%
pivot_longer(cols = c(Hidden.Gem.Score,IMDb.Score,Rotten.Tomatoes.Score,Metacritic.Score), names_to="Score_Type", values_to = "Value")
long_data <- long_data %>% drop_na()
frequency_data <- long_data %>%
group_by(Series.or.Movie, Score_Type, Value) %>%
summarise(Frequency = n())
Plot for “IMDb.Score”, “Hidden.Gem.Score” as they have the range
10
frequency_data %>%
filter(Score_Type %in% c("IMDb.Score", "Hidden.Gem.Score")) %>%
ggplot(aes(x = Value, y = Frequency, color = Score_Type)) +
geom_line() +
facet_wrap(Series.or.Movie ~ Score_Type, ncol = 2) +
scale_y_continuous(trans = "log10") +
labs(x="Score Value")

Challenge 3
netflix_data <- netflix_data %>%
mutate(Production.House = strsplit(as.character(Production.House), ",\\s*")) %>%
unnest(Production.House)
netflix_data$Release.Date <- as.Date(netflix_data$Release.Date, "%m/%d/%Y")
netflix_data <- netflix_data[!is.na(netflix_data$Release.Date), ]
netflix_data$Year <- as.integer(format(netflix_data$Release.Date, "%Y"))
#
netflix_data <- netflix_data %>%
mutate(Production.House = ifelse(Production.House == "Columbia Pictures Corporation", "Columbia Pictures", Production.House)) %>%
mutate(Production.House = ifelse(Production.House == "Warner Bros.", "Warner Brothers", Production.House))
# Summarize total productions by production house
total_productions <- netflix_data %>%
group_by(Production.House) %>%
summarise(Total_Count = n(), .groups = 'drop') %>%
arrange(desc(Total_Count)) %>%
top_n(10, Total_Count)
# Filter the original data to include only the top 10 production houses
filtered_data <- netflix_data %>%
filter(Production.House %in% total_productions$Production.House)
# Summarize by year and production house
summary_data <- filtered_data %>%
group_by(Year, Production.House) %>%
summarise(Count = n(), .groups = 'drop')
# Create a line chart
ggplot(summary_data, aes(x = as.factor(Year), y = Count, color = Production.House, group = Production.House)) +
geom_line() +
geom_point() + # Optional: add points to each data point
theme_minimal() +
labs(x = "Year", y = "Number of Productions", color = "Production House",
title = "Annual Production Count by Top 10 Studios") +
theme(axis.text.x = element_text(angle = 90, hjust = 1),
plot.title = element_text(hjust = 0.5))

ggplot(total_productions, aes(x = reorder(Production.House, Total_Count), y = Total_Count, fill = Production.House)) +
geom_bar(stat = "identity") +
theme_minimal() +
labs(x = "Production House", y = "Total Productions",
title = "Total Productions by Top 10 Studios") +
theme(axis.text.x = element_text(angle = 45, hjust = 1),
plot.title = element_text(hjust = 0.5)) +
guides(fill=guide_legend(title="Production House"))

Ex 1
library(kableExtra)
##
## Attaching package: 'kableExtra'
## The following object is masked from 'package:dplyr':
##
## group_rows
dane <- data %>%
group_by(months) %>%
filter(card=="yes")%>%
summarise(mean = mean(expenditure)) %>%
distinct()
styled_table <- kable(dane, format = "html", caption = "Summary of Monthly Expenditure") %>%
kable_styling(full_width = FALSE) %>%
add_header_above(c("Monthly Expenditure" = 2), align = "center") %>%
column_spec(1, bold = TRUE) %>%
column_spec(2, width = "5em")
styled_table
Summary of Monthly Expenditure
|
Monthly Expenditure
|
|
months
|
mean
|
|
0
|
644.828300
|
|
1
|
149.133178
|
|
2
|
326.831547
|
|
3
|
272.180775
|
|
4
|
458.906625
|
|
5
|
276.954030
|
|
6
|
267.091515
|
|
7
|
223.622225
|
|
8
|
146.884231
|
|
9
|
277.784005
|
|
10
|
389.239306
|
|
11
|
131.747790
|
|
12
|
280.491382
|
|
13
|
274.053157
|
|
14
|
155.206041
|
|
15
|
254.240638
|
|
16
|
251.612847
|
|
17
|
175.455596
|
|
18
|
170.716058
|
|
19
|
247.525100
|
|
20
|
76.019157
|
|
21
|
98.814165
|
|
22
|
255.768994
|
|
23
|
162.250425
|
|
24
|
223.077434
|
|
25
|
198.031739
|
|
26
|
114.450250
|
|
27
|
210.180765
|
|
28
|
203.446343
|
|
29
|
173.365543
|
|
30
|
219.709515
|
|
31
|
58.881943
|
|
32
|
825.464750
|
|
33
|
378.350842
|
|
34
|
69.881679
|
|
35
|
377.027900
|
|
36
|
284.717627
|
|
37
|
139.863146
|
|
38
|
159.249012
|
|
39
|
41.333330
|
|
40
|
183.797500
|
|
41
|
210.422172
|
|
42
|
210.206098
|
|
43
|
399.351957
|
|
44
|
79.431672
|
|
45
|
7.083333
|
|
46
|
568.243300
|
|
47
|
348.244150
|
|
48
|
166.726374
|
|
49
|
69.793152
|
|
50
|
156.201034
|
|
51
|
142.364931
|
|
52
|
198.637478
|
|
53
|
156.546267
|
|
54
|
158.177834
|
|
55
|
38.714160
|
|
56
|
92.724590
|
|
57
|
39.713611
|
|
58
|
61.988350
|
|
59
|
314.996667
|
|
60
|
202.261306
|
|
61
|
86.148330
|
|
62
|
239.822900
|
|
63
|
288.471275
|
|
64
|
238.321154
|
|
65
|
52.580000
|
|
66
|
282.970832
|
|
67
|
345.150000
|
|
68
|
372.622900
|
|
70
|
215.192515
|
|
72
|
370.019727
|
|
74
|
1532.773000
|
|
75
|
323.063300
|
|
76
|
235.715640
|
|
77
|
94.705843
|
|
78
|
272.329723
|
|
80
|
80.450840
|
|
81
|
664.120800
|
|
82
|
412.993300
|
|
84
|
190.366405
|
|
85
|
165.930000
|
|
86
|
35.410279
|
|
87
|
285.255000
|
|
90
|
184.711041
|
|
91
|
187.142500
|
|
93
|
413.202067
|
|
94
|
221.008133
|
|
95
|
633.413300
|
|
96
|
239.660388
|
|
97
|
622.835300
|
|
98
|
503.970000
|
|
99
|
205.513300
|
|
100
|
362.190400
|
|
101
|
22.986670
|
|
102
|
285.297935
|
|
105
|
163.839200
|
|
108
|
267.380829
|
|
109
|
176.040400
|
|
110
|
160.479200
|
|
111
|
63.551670
|
|
113
|
131.674200
|
|
114
|
362.369487
|
|
115
|
43.339170
|
|
117
|
1569.677000
|
|
118
|
159.730000
|
|
120
|
359.839673
|
|
121
|
302.689375
|
|
122
|
319.352065
|
|
123
|
154.859200
|
|
124
|
47.081670
|
|
125
|
212.478300
|
|
126
|
168.259190
|
|
128
|
134.739200
|
|
131
|
97.182065
|
|
132
|
115.493000
|
|
133
|
82.920840
|
|
134
|
82.608335
|
|
135
|
77.286670
|
|
136
|
43.206670
|
|
138
|
278.322790
|
|
143
|
577.983300
|
|
144
|
86.738225
|
|
146
|
310.820817
|
|
147
|
328.973820
|
|
148
|
175.644200
|
|
150
|
148.976468
|
|
151
|
151.880823
|
|
154
|
21.465000
|
|
156
|
289.887210
|
|
158
|
54.969170
|
|
159
|
58.930830
|
|
160
|
349.201700
|
|
161
|
251.520800
|
|
162
|
61.742500
|
|
164
|
461.260000
|
|
166
|
131.765800
|
|
168
|
325.473862
|
|
172
|
192.450800
|
|
177
|
235.571700
|
|
179
|
50.083330
|
|
180
|
240.772283
|
|
182
|
306.031700
|
|
186
|
32.464160
|
|
188
|
54.896255
|
|
192
|
232.222505
|
|
194
|
131.989200
|
|
200
|
81.265000
|
|
201
|
85.240830
|
|
204
|
564.739600
|
|
207
|
185.294985
|
|
210
|
134.918300
|
|
216
|
214.259977
|
|
218
|
92.441670
|
|
220
|
98.682500
|
|
222
|
138.546700
|
|
228
|
264.242080
|
|
229
|
127.118300
|
|
230
|
118.713300
|
|
232
|
101.854200
|
|
233
|
20.250000
|
|
234
|
397.033300
|
|
236
|
260.120800
|
|
240
|
95.569733
|
|
241
|
149.700000
|
|
243
|
79.685000
|
|
244
|
479.436700
|
|
250
|
85.978330
|
|
252
|
83.628322
|
|
264
|
129.393300
|
|
268
|
253.629200
|
|
269
|
220.792500
|
|
270
|
64.074170
|
|
276
|
209.844200
|
|
288
|
91.949150
|
|
300
|
226.589200
|
|
301
|
360.995000
|
|
303
|
634.862500
|
|
372
|
335.562500
|
|
511
|
38.833330
|
|
540
|
182.095800
|