This repository has been archived by the owner on Oct 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
3_dashboard_1.R
66 lines (58 loc) · 2.03 KB
/
3_dashboard_1.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
### 3: Dashboard 1
# load packages
library(shiny)
library(readr)
library(dplyr)
library(ggplot2)
# load data
movies_all <- read_csv("data/movies_all.csv",
col_types = "ccidiif") %>%
# label isHorror factor
mutate(isHorror = factor(isHorror,
levels = c(0, 1),
labels = c("Not horror", "Horror")))
# ui
ui <- fluidPage(
h1("Horror films versus non-horror films", align = "center"), # main title
h2("Average IMDB rating by year", align = "center"), # plot title
plotOutput("plot_rating"), # first plot
h2("Average runtime by year", align = "center"), # plot title
plotOutput("plot_runtime") # second plot
)
# server
server <- function(input, output, session) {
# ggplot: average rating by year for horror films and non-horror films
output$plot_rating <- renderPlot({
ggplot(data = movies_all,
aes(x = releaseYear, y = averageRating,
group = isHorror, colour = isHorror)) +
geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs")) +
labs(x = "Year", y = "Average rating", colour = "Genre") +
theme_bw() +
theme(
legend.position = "bottom",
axis.title = element_text(size = 18),
axis.text = element_text(size = 13),
legend.title = element_text(size = 15),
legend.text = element_text(size = 13),
)
})
# ggplot: average runtime by year for horror films and non-horror films
output$plot_runtime <- renderPlot({
ggplot(data = movies_all,
aes(x = releaseYear, y = runtimeMinutes,
group = isHorror, colour = isHorror)) +
geom_smooth(method = "gam", formula = y ~ s(x, bs = "cs")) +
labs(x = "Year", y = "Runtime (minutes)", colour = "Genre") +
theme_bw() +
theme(
legend.position = "bottom",
axis.title = element_text(size = 18),
axis.text = element_text(size = 13),
legend.title = element_text(size = 15),
legend.text = element_text(size = 13),
)
})
}
# run Shiny app
shinyApp(ui, server)