/
02-otimizacao.R
117 lines (100 loc) · 3 KB
/
02-otimizacao.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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
library(tidyverse)
library(dados)
## ---- fig.width=5, fig.height=4, dpi = 300-------------------------------------
notas_pixar <- pixar_avalicao_publico |>
count(nota_cinema_score) |>
mutate(
nota = fct_explicit_na(nota_cinema_score, "(vazio)"),
nota = fct_relevel(nota, c("A-", "A", "A+", "(vazio)"))
)
notas_pixar |>
ggplot() +
aes(nota, n) +
geom_col(width = .5) +
scale_y_continuous(limits = c(0, 15)) +
labs(title = "A maioria dos filmes da pixar têm nota 'A'") +
theme_minimal(12)
## ---- fig.width=5, fig.height=4, dpi = 300-------------------------------------
notas_pixar |>
mutate(cor = dplyr::case_when(
nota == "A" ~ "b",
TRUE ~ "a"
)) |>
ggplot() +
aes(nota, n, fill = cor) +
geom_col(width = .5, show.legend = FALSE) +
scale_y_continuous(limits = c(0, 15)) +
scale_fill_manual(values = c("gray30", "tomato")) +
labs(title = "A maioria dos filmes da pixar têm nota 'A'") +
theme_minimal(12)
## ----warning=FALSE, fig.width=9, fig.height=6, dpi=300-------------------------
p_size <- notas_pixar |>
mutate(tipo = if_else(nota == "A", "b", "a")) |>
ggplot() +
aes(nota, n, size = tipo) +
geom_segment(aes(xend = nota, yend = 0), size = .5) +
geom_point() +
scale_y_continuous(limits = c(0, 15)) +
scale_size_discrete(range = c(3, 6)) +
theme_minimal(12) +
theme(legend.position = "none")
p_shape <- notas_pixar |>
mutate(tipo = if_else(nota == "A", "b", "a")) |>
ggplot() +
aes(nota, n, shape = tipo) +
geom_segment(aes(xend = nota, yend = 0), size = .5) +
geom_point(size = 6) +
scale_shape_manual(values = c(1, 16)) +
scale_y_continuous(limits = c(0, 15)) +
theme_minimal(12) +
theme(legend.position = "none")
p_mark <- notas_pixar |>
mutate(tipo = if_else(nota == "A", "b", "a")) |>
ggplot() +
aes(nota, n, shape = tipo) +
geom_segment(aes(xend = nota, yend = 0), size = .5) +
geom_point(size = 6) +
scale_shape_manual(values = c(1, 13)) +
scale_y_continuous(limits = c(0, 15)) +
theme_minimal(12) +
theme(legend.position = "none")
p_bar <- notas_pixar |>
mutate(tipo = if_else(nota == "A", "b", "a")) |>
ggplot() +
aes(nota, n) +
geom_col(width = c(.8, .5,.5,.5)) +
scale_y_continuous(limits = c(0, 15)) +
theme_minimal(12)
patchwork::wrap_plots(p_size, p_shape, p_mark, p_bar)
## ---- fig.height=4, fig.width=6, dpi = 300-------------------------------------
pinguins |>
drop_na() |>
ggplot() +
aes(
x = comprimento_bico,
y = profundidade_bico,
shape = especie
) +
geom_point() +
theme_minimal(12) +
labs() +
theme(legend.position = "bottom")
## ---- fig.height=4, fig.width=6, dpi = 300-------------------------------------
pinguins |>
drop_na() |>
ggplot(aes(
x = comprimento_bico,
y = profundidade_bico,
shape = especie,
group = especie
)) +
geom_point() +
theme_minimal(12) +
theme(legend.position = "bottom") +
stat_ellipse(
type = "norm",
geom = "polygon",
alpha = .05,
level = .95,
colour = "transparent"
)