-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathscript_2019-07-02.R
53 lines (44 loc) · 1.78 KB
/
script_2019-07-02.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
library(gameofthrones)
library(ggchicklet)
library(hrbrthemes)
library(tidyverse)
library(glue)
#### Data ####
media_franchises <-
read_csv("data/data_2019-07-02.csv", col_types = "ccddccc") %>%
unique()
#### Table ####
df_biggest <-
media_franchises %>%
group_by(franchise, revenue_category, year_created) %>%
summarise(revenue = sum(revenue)) %>%
ungroup() %>%
mutate(revenue_category = fct_reorder(revenue_category,
revenue, sum, .desc = TRUE),
franchise = fct_lump(franchise, n = 15, w = revenue)) %>%
filter(franchise != "Other") %>%
mutate(franchise = str_remove_all(franchise, "^.*/ "),
franchise = str_remove_all(franchise, " &.*$"),
franchise = glue("{franchise} ({year_created})"),
franchise = fct_reorder(franchise, revenue, sum)) %>%
filter(revenue > 0.5)
#### Plot ####
ggplot(df_biggest) +
aes(x = franchise, y = revenue, fill = revenue_category) +
geom_chicklet(width = 0.75, color = NA, radius = grid::unit(4, "pt")) +
scale_fill_got_d(option = "Daenerys") +
coord_flip() +
guides(fill = guide_legend(override.aes = list(size = 10))) +
labs(x = NULL, y = "Revenue (B$)", fill = NULL,
title = "Highest Grossing Media Franchises",
caption = "Source: Wikipedia\n@_abichat for #TidyTuesday") +
theme_ft_rc() +
theme(legend.position = c(0.8, 0.3),
plot.title = element_text(color = "#929299", hjust = 0.5, size = 25),
axis.title.x = element_text(size = 18),
axis.text.x = element_text(size = 14),
axis.text.y = element_text(size = 14),
legend.text = element_text(size = 15),
plot.caption = element_text(size = 10),
plot.margin = margin(15, 15, 15, 15))
ggsave("plots/plot_2019-07-02.png", width = 29, height = 21, units = "cm", dpi = "retina")