-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathtidytuesday_2021_w34.R
39 lines (34 loc) · 2.05 KB
/
tidytuesday_2021_w34.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
# Load libraries ----------------------------------------------------------
library(tidyverse)
library(treemapify) # For geom_treemap and friends
library(paletteer) # For color palette
library(ggtext) # For customize text (used in this script with element_markdown)
library(ragg) # For the device for save the plot
# Data Reading and Wrangling ----------------------------------------------
computer <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2021/2021-08-17/computer.csv')
characters <- computer %>%
count(char, sort= T)
characters <- characters %>%
mutate(char = factor(char))
characters
# Graphic -----------------------------------------------------------------
# Interpolate color palette to create new color palettes
extended_palette <- colorRampPalette(paletteer_d("rcartocolor::Prism",12))
characters %>%
ggplot(aes(fill = char,area = n, label = glue::glue(" {char} \n ({n})"))) +
geom_treemap(color = "black", size = 1) +
geom_treemap_text(family = "Lato Black",fontface = "italic", colour = "white", place = "centre",
grow = TRUE) +
labs(title = "Which characters interact the most with VUIs\n in the Star Trek Saga?",
caption = "Data from ***SpeechInteraction.com*** and shared by Sara Stoudt.<br>
Tidytuesday Week-34 2021 •<span style='font-family: \"Font Awesome 5 Brands\"'></span>**@issa_madjid**.") +
scale_fill_manual(values = extended_palette(nrow(characters))) +
theme(text =element_text(family = "Lato"),
plot.background = element_rect(fill = "grey95"),
panel.spacing = unit(2.5, units = "cm"),
plot.title = element_text(family = "Lato Black",size = rel(2.5), hjust = .5, margin = margin(t = 15,b = 10)),
plot.caption = element_markdown(color = "black", size = rel(1.2), margin = margin(t = 20,b = 10)),
legend.position = "none"
)
# Saving ------------------------------------------------------------------
ggsave("2021_w34/tidytuesday_2021_w34.png", width = 12.5, height = 12, device = agg_png, dpi = 640)