-
Notifications
You must be signed in to change notification settings - Fork 7
/
treinta.R
80 lines (67 loc) · 2.3 KB
/
treinta.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
# #30díasdegráficos día 30
# Visualización Accidentes de Tránsito Chile 2019
# https://www.conaset.cl/programa/observatorio-datos-estadistica/biblioteca-observatorio/estadisticas-generales/
# Autora: Stephanie Orellana (@sporella)
# Cargar librerías --------------------------------------------------------
library(tidyverse)
library(extrafont)
# loadfonts()
# Cargar y procesar datos -------------------------------------------------
datos <- read_csv("data/accidentes_2019.csv") %>%
pivot_longer(cols = -c(1:2),
names_to = "Lesion",
values_to = "Valor") %>%
mutate(Mes = factor(Mes, levels = c("Enero", "Febrero", "Marzo", "Abril", "Mayo",
"Junio", "Julio", "Agosto", "Septiembre",
"Octubre", "Noviembre", "Diciembre")))
datos_lab <- datos %>%
group_by(Mes) %>%
summarise(n = sum(Valor) + 500)
# Visualización -----------------------------------------------------------
myAng <- seq(-15, -345, length.out = 12)
p <- ggplot() +
geom_col(
data = datos,
aes(x = Mes, y = Valor, fill = Lesion),
width = 1,
colour = "grey33",
size = 0.3,
alpha = 0.7
) +
geom_text(
data = datos_lab,
aes(label = Mes, x = Mes, y = n),
angle = myAng,
size = 2,
fontface = "bold"
) +
coord_polar() +
scale_fill_manual(values = c("#bfe6b4",
"#c2a1c7",
"#64b8c0",
"#e5a28f")) +
labs(
title = "Consecuencias de Accidentes de Tránsito en Chile\nAÑO 2019",
x = "",
y = "",
fill = "",
caption = "@sporella"
) +
theme(
text = element_text(family = "Gill Sans MT Condensed"),
legend.position = "bottom",
axis.text.x = element_blank(),
panel.grid = element_line(linetype = "dotted", colour = "grey50"),
plot.background = element_rect(fill = "grey92"),
legend.background = element_rect(fill = "grey92"),
panel.background = element_rect(fill = "grey92"),
panel.spacing = unit(1, "mm"),
plot.title = element_text(family = "Gill Sans MT Condensed", hjust = 0.5)
) +
guides(fill = guide_legend(
nrow = 2,
keywidth = unit(3, "mm"),
keyheight = unit(3, "mm")
))
p
ggsave("plots/treinta/nightingale.png", p, width = 4, height = 5)