-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlego.R
68 lines (51 loc) · 2.38 KB
/
lego.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
67
68
################################################################################
author: Patrick Stephenson (@stepminer2)
purpose: tidytuesday, week of 09-06-2022
################################################################################
library(tidyverse)
library(tidyquant)
library(showtext)
# add fonts
font_add_google(name = "Grandstander", family = "Grandstander")
font_add_google(name = "Bebas Neue", family = "Bebas Neue")
showtext_auto()
inventories <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-09-06/inventories.csv.gz')
inventory_sets <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-09-06/inventory_sets.csv.gz')
sets <- readr::read_csv('https://raw.githubusercontent.com/rfordatascience/tidytuesday/master/data/2022/2022-09-06/sets.csv.gz')
all_df <- left_join(inventories, inventory_sets, by = "set_num") |>
left_join(sets, by = "set_num")
#EXPLORE
DataExplorer::create_report(all_df)
skimr::skim(all_df)
all_df %>% arrange(desc(num_parts))
df<- all_df %>%
# mutate(num_parts_log= log10(num_parts))%>%
select(name, year,num_parts)%>%
group_by(year)%>%
summarise(av = mean(num_parts+1 )) %>%
ungroup()
df%>%
# Setup canvas with year (x-axis) and sales (y-axis)
ggplot(aes(x = year, y = av)) +
# Geometries
geom_point(size = 0.5, color = "#2c3e50") +
# geom_label(aes(label = sales_text)) +
geom_smooth(method = "lm", se = FALSE) +
# Formatting
theme_tq(base_family ="Bebas Neue", base_size = 30 ) +
theme(
plot.title = element_text(family = "Bebas Neue", size = 80, colour = "black",
margin = margin(t = 20, b = 10)),
plot.subtitle = element_text(family = "Bebas Neue", size = 60, colour = "black",
margin = margin(b = 20)),
plot.caption = element_text(color = "black", size = 24, hjust = 0.5)
)+
# scale_y_continuous(labels = scales::dollar) +
labs(
title = "LEGO MOCs Mean Number of parts by Year",
subtitle = "There seems to exist an Upward trend",
x = "",
y = "Number of parts",
caption = "Visualization: stepminer2 | Data: rebrickable courtesy of Georgios Karamanis"
)
ggsave("lego.png", width = 8.5, height = 7, units = "in", dpi=320)