-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathbar_chart.R
66 lines (53 loc) · 1.58 KB
/
bar_chart.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
# Setup -------------------------------------------------------------------
library('tidyverse')
tuesdata <- tidytuesdayR::tt_load("2021-06-29")
# Exploratory data analysis -----------------------------------------------
animal_rescues <- tuesdata$animal_rescues
glimpse(animal_rescues)
animal_rescues %>%
group_by(animal_group_parent, cal_year) %>%
add_count(name = "animal_rescue_counts")
data <-
animal_rescues %>%
mutate(
animal_group_parent = recode(animal_group_parent,
cat = "Cat",
Budgie = "Bird",
Pigeon = "Bird"
),
animal_group_parent = case_when(
str_detect(animal_group_parent, "Unknown") ~ "Unknown",
TRUE ~ animal_group_parent
),
across(where(is.character), factor)
) %>%
filter(cal_year == "2020") %>%
group_by(animal_group_parent) %>%
count() %>%
ungroup() %>%
summarise(animal_group_parent,
proportion = n / sum(n),
)
ggplot(
data,
aes(x = reorder(animal_group_parent, proportion), y = proportion, fill = animal_group_parent)
) +
geom_col(show.legend = FALSE) +
coord_flip() +
scale_y_continuous(
name = "",
labels = scales::label_percent(accuracy = 1)
) +
gghighlight::gghighlight(animal_group_parent == "Cat") +
ggbrookings::theme_brookings() +
ggbrookings::scale_fill_brookings() +
labs(
title = "Cats are adorable but also clumsy",
subtitle = "Animal rescues in 2020",
x = "",
caption = '**Source:** The Guardian'
)
ggsave(here::here('01-animal-rescue', 'bar_chart.png'),
width=85 * (14/5), height=53 * (14/5),
units = 'mm',
dpi = 300)