ggchicklet: Create Chicklet (Rounded Segmented Column) Charts

ggchicklet: Create Chicklet (Rounded Segmented Column) Charts

This is my note for learning ggchicklet: Create Chicklet (Rounded Segmented Column) Charts and 100% Stacked Chicklets.

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
# remotes::install_github("hrbrmstr/ggchicklet")
library(ggchicklet)
library(tidyverse)
data("debates2019")
debates2019 %>%
dplyr::filter(debate_group == 1) %>%
mutate(speaker = fct_reorder(speaker, elapsed, sum, .desc = FALSE)) %>%
mutate(topic = fct_other(
topic,
c("Immigration", "Economy", "Climate Change", "Gun Control", "Healthcare", "Foreign Policy")
)) %>%
ggplot(aes(speaker, elapsed, group = timestamp, fill = topic)) +
geom_chicklet(width = 0.75) +
scale_y_continuous(
expand = c(0, 0.0625),
position = "right",
breaks = seq(0, 14, 2),
labels = c(0, sprintf("%d min", seq(2, 14, 2)))
) +
scale_fill_manual(
name = NULL,
values = c(
"Immigration" = "#ae4544",
"Economy" = "#d8cb98",
"Climate Change" = "#a4ad6f",
"Gun Control" = "#cc7c3a",
"Healthcare" = "#436f82",
"Foreign Policy" = "#7c5981",
"Other" = "#cccccc"
),
breaks = setdiff(unique(debates2019$topic), "Other")
) +
guides(fill = guide_legend(nrow = 1)) +
coord_flip() +
labs(x = NULL, y = NULL, fill = NULL,
title = "How long Each Candidate Spoke",
subtitle = "NIghts 1 & 2 of the June 2019 Democratic Debates",
caption = "Each bar segment represents the length of a candidate's response to a question.\n\nOriginals<https://www.nytimes.com/interactive/2019/admin/100000006581096.embedded.html?>\n<https://www.nytimes.com/interactive/2019/admin/100000006584572.embedded.html?>\nby @nytimes Weiyi Cai, Jason Kao, Jasmine C. Lee, Alicia Parlapiano and Jugal K. Patel\n\n#rstats reproduction by @hrbrmstr") +
theme_ipsum(base_family = enfont,
grid = "X") +
theme(axis.text.x = element_text(color = "gray60", size = 10),
legend.position = "top")

100% Stacked Chicklets:

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
debates2019 %>% 
dplyr::filter(debate_group == 1) %>%
mutate(speaker = fct_reorder(speaker, elapsed, sum, .desc = FALSE)) %>%
mutate(topic = fct_other(
topic,
c("Immigration", "Economy", "Climate Change", "Gun Control", "Healthcare", "Foreign Policy")
)) %>%
ggplot(aes(speaker, elapsed, group = timestamp, fill = topic)) +
geom_chicklet(width = 0.75, position = position_fill()) +
scale_y_percent(expand = c(0, 0.0001), position = "right") +
scale_fill_manual(
name = NULL,
values = c(
"Immigration" = "#ae4544",
"Economy" = "#d8cb98",
"Climate Change" = "#a4ad6f",
"Gun Control" = "#cc7c3a",
"Healthcare" = "#436f82",
"Foreign Policy" = "#7c5981",
"Other" = "#cccccc"
),
breaks = setdiff(unique(debates2019$topic), "Other")
) +
guides(fill = guide_legend(nrow = 1)) +
coord_flip() +
labs(x = NULL, y = NULL, fill = NULL,
title = "How long Each Candidate Spoke",
subtitle = "NIghts 1 & 2 of the June 2019 Democratic Debates",
caption = "Each bar segment represents the length of a candidate's response to a question.\n\nOriginals<https://www.nytimes.com/interactive/2019/admin/100000006581096.embedded.html?>\n<https://www.nytimes.com/interactive/2019/admin/100000006584572.embedded.html?>\nby @nytimes Weiyi Cai, Jason Kao, Jasmine C. Lee, Alicia Parlapiano and Jugal K. Patel\n\n#rstats reproduction by @hrbrmstr") +
theme_ipsum(base_family = enfont,
grid = "X") +
theme(axis.text.x = element_text(color = "gray60", size = 10),
legend.position = "top")

# R

Comments

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×