-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathREADME.Rmd
230 lines (166 loc) · 6.23 KB
/
README.Rmd
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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
---
output: github_document
---
<!-- README.md is generated from README.Rmd. Please edit that file -->
```{r, echo = FALSE}
knitr::opts_chunk$set(
collapse = TRUE,
comment = "#>",
fig.path = "figures/",
fig.width = 6,
fig.height = 4,
out.width = '80%',
fig.align = "center"
)
```
# Rokemon <img src="man/figures/logo.png" align="right" height="125px"/>
An R package to create Pokemon inspired ggplots. It also comes with dataset of 801 Pokemon
with 41 different features (Gotta analyze'em all!).
## Overview
For more details and examples see next sections.
Data
* `pokemon`: Data frame containing attributes and stats of 801 Pokemon.
Functions
* `gghealth()`: HP bar inspired Bar charts.
* `poke_pie()`: create pie charts from color distribution of Pokemon sprites.
Themes
* `theme_rocket()`: Team Rocket theme
* `theme_gameboy()` and `theme_gba()`: classic Gameboy and Gameboy Advanced themes
* `theme_status()`: inspired by Pokemon status bar
* `theme_mystic()`, `theme_valor()`, `theme_instinct()`: Pokemon Go teams theme; work well with
`annotate_pogo()`
* `scale_color_poketype()` and `scale_fill_poketype()`: Provides colors, if Pokemon types are mapped to color/fill
Pokemon Palettes
* `poke_pal()`: color palettes created from Pokemon sprites
* `display_poke_pal()`: view a Pokemon color palette
## Install
The developer version can be obtained from github.
```{r install, eval = FALSE}
#install.packages("devtools")
devtools::install_github("schochastics/Rokemon")
```
```{r load-libs,message=FALSE,warning=FALSE}
library(Rokemon)
library(tidyverse)
data(pokemon)
```
## Themes
The package includes several themes for ggplot.
### Theme Rocket
*(See what I did there...)*
```{r theme-rocket}
ggplot(pokemon,aes(attack,defense))+
geom_point(col = "grey")+
theme_rocket()+
labs(x = "Jessy",y = "James",
title = "Theme Rocket",
subtitle = "blast off at the speed of light!",
caption = "meowth that's right")
```
### Gamyboy theme
If you want to get nostalgic.
```{r theme-gameboy}
ggplot(pokemon,aes(attack,defense))+
geom_point(shape = 15,col = "#006400",size=2)+
theme_gameboy()+
labs(title = "Classic Gameboy Theme")
```
```{r theme-gba}
ggplot(pokemon,aes(attack,defense))+
geom_point(shape = 15,col = "#27408B",size=2)+
theme_gba()+
labs(title = "Gameboy Advanced Theme")
```
### Status theme and HP bar chart
A theme inspired by HP bar in older Pokemon games. The theme is used in `gghealth`,
a function that plots bar charts in HP bar style.
```{r gghealth}
pokemon[1:10,] %>%
gghealth("name","base_total",init.size = 5)+
labs(x="",y="Stats Total")
```
### Pokemon Go
Annotate your plots with the logo of your favorite Pokémon Go team.
```{r pogo-teams,fig.height=4,fig.width=10}
p1 <- pokemon %>%
dplyr::filter(type1=="water") %>%
ggplot(aes(defense,attack))+geom_point()+annotate_pogo(team = "mystic")+theme_mystic()+
labs(title="Team Mystic",subtitle="Water Pokemon")
p2 <- pokemon %>%
dplyr::filter(type1=="fire") %>%
ggplot(aes(defense,attack))+geom_point()+annotate_pogo(team = "valor")+theme_valor()+
labs(title="Team Valor",subtitle="Fire Pokemon")
p3 <- pokemon %>%
dplyr::filter(type1=="electric") %>%
ggplot(aes(defense,attack))+geom_point()+annotate_pogo(team = "instinct")+theme_instinct()+
labs(title="Team Instinct",subtitle="Electric Pokemon")
gridExtra::grid.arrange(grobs=list(p1,p2,p3),ncol=3)
```
## Poke Pie
Create pie charts of the color distribution of Pokemon sprites. Download all sprites, for
example from [here](https://github.com/PokeAPI/sprites).
```{r poke-pie,eval=FALSE}
#basic usage
poke_pie(path_to_sprites,pokemon_name)
```
![](figures/poke-pies.png)
The function is a reimplementation of [this](https://gist.github.com/need12648430/4d681c9d1b18745ce159)
code, which was posted on [reddit](https://www.reddit.com/r/pokemon/comments/2ey1pw/last_night_i_wrote_a_processing_script_that/ck45c21/) a while ago.
## Color Palettes
The package also includes color palettes, which were automatically generated from
all 801 pokemon sprites.
```{r poke-pals,eval=FALSE}
poke_pal(name,n)
display_poke_pal(name)
```
![](figures/palettes.png)
Additionally there is also a palette Pokemon Types, used by `scale_color_poketype()` and
`scale_fill_poketype()`.
![](figures/rocket-type-pal.png)
I did not check all Pokemon palettes, so there may well be
some meaningless ones. A better alternative would be to use the dedicated package `palettetown`.
See the github [repo](https://github.uint.cloudt/imcdlucas/palettetown) for help.
```{R palettes, eval=FALSE}
install.packages('palettetown')
```
## Fonts
The package uses an old school gameboy font for some of its themes, which
can be download [here](https://github.com/Superpencil/pokemon-font/releases/tag/v1.8.1).
In order to use the font in R you need the `extrafont` package.
```{R install-fonts, eval=FALSE}
#install.packages("extrafont")
extrafont::font_import() #only run ones
extrafont::loadfonts()
```
Alternatively, you can use the function `import_pokefont()`.
```{r import-fonts,eval=FALSE}
import_pokefont()
```
## Example use of data
Using `theme_rocket()` to create an effectiveness table of Pokemon types.
```{r effectiveness,fig.width=9,fig.height=6}
pokemon %>%
distinct(type1,.keep_all=TRUE) %>%
select(defender = type1,against_bug:against_water) %>%
gather(attacker,effect,against_bug:against_water) %>%
mutate(attacker = str_replace_all(attacker,"against_","")) %>%
ggplot(aes(y=attacker,x=defender,fill=factor(effect)))+
geom_tile()+
geom_text(aes(label=ifelse(effect!=1,effect,"")))+
scale_fill_manual(values=c("#8B1A1A", "#CD2626", "#EE2C2C", "#FFFFFF", "#00CD00", "#008B00"))+
theme_rocket(legend.position="none")+
labs(title="Effectiveness Table")
```
Using Pokemon type colors
```{r poketype-colors}
ggplot(pokemon,aes(defense,attack))+
geom_point(aes(col=type1))+
scale_color_poketype()+
theme_bw()
```
## Addendum
* Logo created by [ZeroDawn0D](https://github.com/ZeroDawn0D)
* Pogo Logos downloaded [here](https://dribbble.com/shots/2831980-Pok-mon-GO-Team-Logos-Vector-Download)
* Pokémon data download from [Kaggle](https://www.kaggle.com/rounakbanik/pokemon), originally
scraped from [serebii.net](http://serebii.net/)
* Sprites for `poke_pie` can be found [here](https://github.com/PokeAPI/sprites)