-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlab01.R
56 lines (42 loc) · 1.56 KB
/
lab01.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
library(tidyverse)
# leitura -----------------------------------------------------------------
olist <- arrow::read_parquet(
"https://github.com/jtrecenti/202431-padsv/releases/download/dados/olist_items.parquet"
)
# exercício 1 ----------------------------------------------------------
contagem <- olist %>%
count(types) %>%
filter(n > 100)
df_plot1 <- data.frame(
types = contagem$types, frequencia = contagem$n
)
df_plot1$types <- factor(df_plot1$types, levels = df_plot1$types[order(df_plot1$frequencia)])
df_plot1 <- df_plot1 |>
mutate(
types = fct_reorder(types, frequencia)
)
plot1 <- df_plot1 |>
ggplot(aes(x = frequencia / 1000, y = types, label = round(frequencia / 1000, 2))) +
geom_col(fill = "#A8E1D7", width = 0.5) +
labs(
title = "Formas de pagamento mais comuns",
subtitle = "Considerando tipos com mais de 100 observações",
x = "Quantidade\n(milhares)",
y = "Formas de pagamento",
fill = "Formas de pagamento",
caption = "Fonte: Olist"
) +
geom_label(
aes(x = frequencia / 1000 / 2)
) +
theme(
panel.background = element_rect(fill = "gray20"),
plot.background = element_rect(fill = "gray10"),
text = element_text(color = "white", family = "serif"),
axis.text = element_text(color = "white", family = "serif"),
panel.grid.minor = element_blank()
)
print(plot1)
# exercício 2 ----------------------------------------------------------
# exercício 3 ----------------------------------------------------------
# exercício 4 ----------------------------------------------------------