Nama : Ayla Huwaida
NIM : 2511017120006
Program Studi : Statistika
Mata Kuliah : Komputasi Statistika 1
Dosen Pengampu : Rifqi Aulya Rahman
library(tidyverse)
## Warning: package 'tidyverse' was built under R version 4.5.3
## Warning: package 'ggplot2' was built under R version 4.5.3
## Warning: package 'tidyr' was built under R version 4.5.3
## Warning: package 'purrr' was built under R version 4.5.3
## Warning: package 'dplyr' was built under R version 4.5.3
## Warning: package 'stringr' was built under R version 4.5.3
## Warning: package 'lubridate' was built under R version 4.5.3
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr 1.2.1 ✔ readr 2.2.0
## ✔ forcats 1.0.1 ✔ stringr 1.6.0
## ✔ ggplot2 4.0.3 ✔ tibble 3.3.1
## ✔ lubridate 1.9.5 ✔ tidyr 1.3.2
## ✔ purrr 1.2.2
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
data_raw <- read.csv("https://raw.githubusercontent.com/reisanar/datasets/master/HollywoodMovies.csv")
data_film <- data_raw[!is.na(data_raw$RottenTomatoes) & !is.na(data_raw$AudienceScore), ]
data_film$Label_HP <- ifelse(grepl("Harry Potter",data_film$Movie),"Film Harry Potter", "Film Lainnya")
data_film$Label_HP <- factor(data_film$Label_HP,levels = c("Film Harry Potter", "Film Lainnya"))
glimpse(data_film)
## Rows: 907
## Columns: 17
## $ Movie <chr> "Spider-Man 3", "Shrek the Third", "Transformers", "P…
## $ LeadStudio <chr> "Sony", "Paramount", "Paramount", "Disney", "Warner B…
## $ RottenTomatoes <int> 61, 42, 57, 45, 78, 69, 93, 31, 26, 60, 97, 90, 14, 9…
## $ AudienceScore <int> 54, 57, 89, 74, 82, 69, 91, 72, 73, 90, 84, 78, 72, 8…
## $ Story <chr> "Metamorphosis", "Quest", "Monster Force", "Rescue", …
## $ Genre <chr> "Action", "Animation", "Action", "Action", "Adventure…
## $ TheatersOpenWeek <int> 4252, 4122, 4011, 4362, 4285, 3606, 3660, 3832, 3475,…
## $ OpeningWeekend <dbl> 151.1, 121.6, 70.5, 114.7, 77.1, 77.2, 69.3, 44.8, 44…
## $ BOAvgOpenWeekend <int> 35540, 29507, 17577, 26302, 17998, 21411, 18929, 1168…
## $ DomesticGross <dbl> 336.53, 322.72, 319.25, 309.42, 292.00, 256.39, 227.4…
## $ ForeignGross <dbl> 554.34, 476.24, 390.46, 654.00, 647.88, 328.96, 215.3…
## $ WorldGross <dbl> 890.87, 798.96, 709.71, 963.42, 939.89, 585.35, 442.8…
## $ Budget <dbl> 258.0, 160.0, 150.0, 300.0, 150.0, 150.0, 110.0, 130.…
## $ Profitability <dbl> 345.30, 499.35, 473.14, 321.14, 626.59, 390.23, 402.5…
## $ OpenProfit <dbl> 58.57, 76.00, 47.00, 38.23, 51.40, 51.47, 63.00, 34.4…
## $ Year <int> 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007, 2007,…
## $ Label_HP <fct> Film Lainnya, Film Lainnya, Film Lainnya, Film Lainny…
ringkasan <- aggregate(cbind(RottenTomatoes, AudienceScore) ~ Label_HP,
data = data_film, FUN = mean)
names(ringkasan)[2:3] <- c("rata_RT", "rata_aud")
ringkasan
## Label_HP rata_RT rata_aud
## 1 Film Harry Potter 84.00000 84.00000
## 2 Film Lainnya 51.60354 61.17054
4.Density Plot Dasar
palet_hp <- c("Film Harry Potter" = "#F48FB1",
"Film Lainnya" = "#81D4FA")
gd <- ggplot(data_film, aes(x = RottenTomatoes))
gd +
geom_density(fill = "#81D4FA", alpha = 0.5, outline.type = "full") +
geom_vline(xintercept = mean(data_film$RottenTomatoes),
color = "#FC4E07", linetype = "dashed", size = 1)
## Warning: Using `size` aesthetic for lines was deprecated in ggplot2 3.4.0.
## ℹ Please use `linewidth` instead.
## This warning is displayed once per session.
## Call `lifecycle::last_lifecycle_warnings()` to see where this warning was
## generated.
5. Density Plot per Kelompok + Theme Final
p <- ggplot(data_film, aes(x = RottenTomatoes, fill = Label_HP))
p
p <- p +
geom_density(alpha = 0.4, outline.type = "full")
p
p <- p +
geom_vline(data = ringkasan,
aes(xintercept = rata_RT, color = Label_HP),
linetype = "dashed",
size = 1)
p
p <- p +
scale_fill_manual(values = palet_hp) +
scale_color_manual(values = palet_hp)
p
p <- p +
labs(
title = "Distribusi Skor Kritikus Film Hollywood (2007-2011)",
subtitle = "Harry Potter vs Film Lainnya - Rotten Tomatoes Score",
x = "Skor Rotten Tomatoes",
y = "Kepadatan",
fill = "Kategori Film",
color = "Rata-rata per Grup",
caption = "Sumber: reisanar/datasets via GitHub"
)
p
p <- p +
theme_minimal(base_size = 10) +
theme(
plot.title = element_text(face = "bold", size = 13),
plot.subtitle = element_text(face = "italic", size = 9,
color = "gray40"),
panel.grid.minor = element_blank(),
legend.position = "bottom"
)
p
This is an R Markdown document. Markdown is a simple formatting syntax for authoring HTML, PDF, and MS Word documents. For more details on using R Markdown see http://rmarkdown.rstudio.com.
When you click the Knit button a document will be generated that includes both content as well as the output of any embedded R code chunks within the document. You can embed an R code chunk like this:
summary(cars)
## speed dist
## Min. : 4.0 Min. : 2.00
## 1st Qu.:12.0 1st Qu.: 26.00
## Median :15.0 Median : 36.00
## Mean :15.4 Mean : 42.98
## 3rd Qu.:19.0 3rd Qu.: 56.00
## Max. :25.0 Max. :120.00
You can also embed plots, for example:
Note that the echo = FALSE parameter was added to the
code chunk to prevent printing of the R code that generated the
plot.