-
Notifications
You must be signed in to change notification settings - Fork 0
/
script.r
120 lines (94 loc) · 4.42 KB
/
script.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
115
116
117
118
119
120
library(tidyverse)
library(glue)
library(readr)
library(ggrepel)
library(ggimage)
library(gghighlight)
source("src/plot.r")
## Data Loading
pokemon <- read_csv("data/pokemon.csv", col_types = cols(capture_rate = col_double()))
image <- read_csv("data/image.csv") %>%
select(Number, Pokemon, PNG) %>%
mutate(local_img=glue("data/pokemon_img/{Number}.png"))
first_generation <- pokemon %>%
filter(generation==1) %>%
left_join(., image, by=c("pokedex_number" ="Number")) %>%
mutate(
att_def_ratio=attack/defense,
sum_att_def=attack+defense,
hp_def_ratio=hp/defense,
) %>%
filter(hp<200)
plot_family <- function(data, family){
ratio_quantiles <- seq(0, 4, 0.25)
plot <- ggplot(data) +
geom_gridline_ratio(max_x=max(data$defense), ratio_quantiles) +
geom_image(aes(x=defense, y=attack, label=name, image=PNG), size=.1) +
gghighlight(pokedex_number %in% family) +
coord_cartesian(xlim = c(0, 185), ylim = c(0, 180)) +
scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0)) +
labs(x="Defense", y="Attack") +
custom_theme()
}
## Attack Defense plot
### Classic grid
attack_defense_plot <- ggplot(first_generation) +
geom_image(aes(x=defense, y=attack, label=name, image=PNG), size=.06) +
coord_cartesian(xlim = c(0, 185), ylim = c(0, 180)) +
scale_x_continuous(expand = c(0, 0)) +
scale_y_continuous(expand = c(0, 0)) +
labs(x="Defense", y="Attack") +
custom_theme_with_grid()
attack_defense_plot + ggsave("img/attack_defense_classic_plot.png", bg="white", width = 50, height = 30, units = "cm", dpi = 300)
### Cumul
ratio_quantiles <- quantile(first_generation$sum_att_def, probs=seq(0, 1, 0.1))
# ratio_quantiles <- seq(0, 400, 25)
attack_defense_plot_bis <- ggplot(first_generation) +
geom_gridline_cumul(ratio_quantiles) +
geom_image(aes(x=defense, y=attack, label=name, image=PNG), size=.06) +
coord_cartesian(xlim = c(0, 185), ylim = c(0, 180)) +
scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0)) +
labs(x="Defense", y="Attack") +
custom_theme()
attack_defense_plot_bis + ggsave("img/attack_defense_plot_bis.png", bg="white", width = 50, height = 30, units = "cm", dpi = 300)
### Ratio
# ratio_quantiles <- quantile(first_generation$att_def_ratio, probs=seq(0, 1, 0.1))
ratio_quantiles <- seq(0, 4, 0.25)
attack_defense_plot <- ggplot(first_generation) +
geom_gridline_ratio(max_x=max(first_generation$defense), ratio_quantiles) +
geom_image(aes(x=defense, y=attack, label=name, image=PNG), size=.06) +
coord_cartesian(xlim = c(0, 185), ylim = c(0, 180)) +
scale_x_continuous(expand = c(0, 0)) + scale_y_continuous(expand = c(0, 0)) +
labs(x="Defense", y="Attack") +
custom_theme()
attack_defense_plot + ggsave("img/attack_defense_plot.png", bg="white", width = 50, height = 30, units = "cm", dpi = 300)
### Family ratio
attack_defense_plot_filter_poli_family <- plot_family(first_generation, c(25))
attack_defense_plot_filter_poli_family + ggsave("img/attack_defense_plot_filter_poli_family.png", bg="white", width = 50, height = 30, units = "cm", dpi = 300)
values <- quantile(first_generation$capture_rate/first_generation$att_def_ratio, probs=seq(0, 1, 0.1))
test_plot <- ggplot(first_generation) +
geom_image(aes(x=att_def_ratio, y=capture_rate, label=name, image=PNG), size=.05) +
# gghighlight(pokedex_number %in% c(1,2,3,4,5,6,7,8,9)) +
labs(x="Att/Def ratio", y="Capture Rate") +
geom_gridline_ratio(max(first_generation$att_def_ratio), values) +
custom_theme()
test_plot + ggsave("img/test_plot.png", bg="white", width = 50, height = 30, units = "cm", dpi = 300)
test_data <- ggplot(first_generation) +
geom_image(aes(x=base_total, y=attack, label=name, image=PNG), size=.05) +
labs(x="Base", y="Attack")
### Product ratio
values <- seq(0, 250, 25)
ratio_product_plot <- ggplot(first_generation) +
geom_image(aes(x=hp, y=att_def_ratio, label=name, image=PNG), size=.06) +
map(values, function(v){
list(
stat_function(fun=function(x) v / x, linetype="dashed", color="#8F9194")
)
}
) +
coord_cartesian(xlim = c(0, max(first_generation$hp) + 20), ylim = c(0, max(first_generation$att_def_ratio) + 0.5)) +
scale_x_continuous(expand = c(0, 0), limits=c(0, 300)) +
scale_y_continuous(expand = c(0, 0)) +
labs(x="Hit Points", y="Attack/Defense Ratio") +
custom_theme()
ratio_product_plot + ggsave("img/ratio_product_plot.png", bg="white", width = 50, height = 30, units = "cm", dpi = 300)