-
Notifications
You must be signed in to change notification settings - Fork 7
/
cuatro.R
74 lines (59 loc) · 2.32 KB
/
cuatro.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
# #30díasdegráficos día 4
# Visualización habilidades pokemon set de Datos de miércoles
# https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-07-10/pokemon.csv
# Autora: Stephanie Orellana (@sporella)
# Cargar librerías --------------------------------------------------------
library(tidyverse)
library(ggimage)
library(extrafont)
# Instalar fuente pokemon:
# https://fontmeme.com/fuentes/fuente-pokmon/
extrafont::loadfonts()
# Cargar y procesar datos -------------------------------------------------
pokemon <- read_csv("https://raw.githubusercontent.com/cienciadedatos/datos-de-miercoles/master/datos/2019/2019-07-10/pokemon.csv")
pokemon_long <- pokemon %>%
pivot_longer(cols = puntos_vida:velocidad, names_to = "habilidad") %>%
group_by(tipo_1, habilidad) %>%
summarise(total = mean(value)) %>%
mutate(habilidad = str_to_title(str_replace_all(string = habilidad, pattern = "_", replacement = " ")))
# Visualización -----------------------------------------------------------
p <-ggplot(pokemon_long, aes(x=habilidad, y=total, fill=habilidad))+
geom_col(alpha=0.9) +
facet_wrap(~tipo_1) +
scale_x_discrete(expand = c(0,0))+
labs(title = "Pokémon",
subtitle = "Cuadro de Habilidades",
x = "",
y = "Valor",
fill = "",
caption = "@sporella")+
scale_fill_manual(values = c("#205500",
"#73356b",
"#b248b8",
"#ff68a9",
"#ffaa52",
"#00d8b2"))+
theme_dark()+
theme(text = element_text(family = "Bahnschrift"),
axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
plot.subtitle = element_text(
colour = "grey15",
family = "Bahnschrift",
size = 20,
hjust = 0.5,
vjust = 0.5
),
plot.title = element_text(
colour = "grey15",
family = "Pokemon Solid",
size = 50,
hjust = 0.5,
vjust = 0.5
),
legend.position = "bottom"
)
# * Incluir fondo con paquete ggimage -------------------------------------
back <- ("img/pokemon.png")
pf <- ggbackground(p, back)
ggsave("plots/cuatro/habilidades_pokemon.png", pf, width = 7.31, height = 5.46)