-
Notifications
You must be signed in to change notification settings - Fork 7
/
doce.R
71 lines (53 loc) · 2.38 KB
/
doce.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
# #30díasdegráficos día 12
# Visualización rendimientos y salarios FIFA20
# https://www.kaggle.com/sagunsh/fifa-20-complete-player-dataset
# Autora: Stephanie Orellana (@sporella)
# Cargar librerías --------------------------------------------------------
library(tidyverse)
library(janitor)
library(ggimage)
# Cargar y procesar datos -------------------------------------------------
data <- read_csv("data/fifa20_data.csv") %>%
clean_names()
# * Función para rescatar imágenes de web nueva ---------------------------
fix_pic <- Vectorize(function(x){
m <- str_match(x, "(\\d{0,3})(\\d{3,4}).png")
paste0("https://cdn.sofifa.com/players/", str_pad(m[2], width = 3, pad="0"), "/", m[3], "/20_60.png")
})
datos <- data %>%
mutate(wage2 = as.numeric(str_extract(wage, pattern = "[:digit:]+"))) %>%
top_n(15, wt = wage2) %>%
mutate(foto_fix = fix_pic(image))
# Visualización -----------------------------------------------------------
colores <- c("#b4c7ff",
"#f1eb9d",
"#d59abc",
"#b2ffec",
"#6fb8b0")
p <- ggplot(datos, aes(x = name)) +
geom_segment( aes(xend = name, y = 0, yend = wage2), colour = "grey80", size = 1) +
geom_segment( aes(xend = name, y = 0, yend = overall, colour = club), size = 1) +
geom_point(aes(y = wage2), colour = "grey80", size = 8, show.legend = F) +
geom_point(aes(y = overall, color = club, fill = club), size = 8, show.legend = F) +
geom_text(aes(y = overall, label = overall )) +
geom_image(aes(image = foto_fix, y = -10, size = 0.1, by = "height")) +
scale_colour_manual(values = colores)+
scale_y_continuous(
sec.axis = dup_axis(name = "Salario(€K)"),
expand = expansion(mult = c(.1, .1))
)+
scale_size_identity() +
labs(title ="Salario v/s Rendimiento",
subtitle = "Los 15 mejor pagados del juego FIFA20",
caption = "@sporella", y = "Rendimiento General",
x = "", colour = "Club") +
theme_minimal() +
theme(axis.text.x = element_text(angle = 90, vjust = 0.5, hjust = 1),
legend.position = "bottom",
axis.title.y.left = element_text(hjust = 0 ),
axis.title.y.right = element_text(hjust = 0),
plot.title = element_text(size = 30, face ="bold"),
plot.subtitle = element_text(size = 20)
) +
guides(colour = guide_legend(override.aes = list(size = 2)))
ggsave("plots/doce/fifa20.png",p, width = 8, height = 8)