Learn R Programming

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

From CRAN

not released yet

Developers version

#install.packages("devtools")
devtools::install_github("schochastics/Rokemon")
library(Rokemon)
library(tidyverse)

data(pokemon)

Themes

The package includes several themes for ggplot.

Theme Rocket

(See what I did there...)

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.

ggplot(pokemon,aes(attack,defense))+
  geom_point(shape = 15,col = "#006400",size=2)+
  theme_gameboy()+
  labs(title = "Classic Gameboy Theme")
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.

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.


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.

#basic usage
poke_pie(path_to_sprites,pokemon_name)

The function is a reimplementation of this code, which was posted on reddit a while ago.

Color Palettes

The package also includes color palettes, which were automatically generated from all 801 pokemon sprites.

poke_pal(name,n)
display_poke_pal(name)

Additionally there is also a palette Pokemon Types, used by scale_color_poketype() and scale_fill_poketype().

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 for help.

install.packages('palettetown')

Fonts

The package uses an old school gameboy font for some of its themes, which can be download here.

In order to use the font in R you need the extrafont package.

#install.packages("extrafont")
extrafont::font_import() #only run ones
extrafont::loadfonts()

Alternatively, you can use the function import_pokefont().

import_pokefont()

Example use of data

Using theme_rocket() to create an effectiveness table of Pokemon types.

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

ggplot(pokemon,aes(defense,attack))+
  geom_point(aes(col=type1))+
  scale_color_poketype()+
  theme_bw()

Addendum

The package is in an early stage, so expect some caterpies bugs

Copy Link

Version

Version

0.0.1

License

MIT + file LICENSE

Maintainer

David Schoch

Last Published

September 14th, 2018

Functions in Rokemon (0.0.1)

poke_pal

Pokemon inspired Palettes
poke_pie

Poke Pie Charts
pokemon

Pokemon Data
scale_color_poketype

Pokemon color scale
gghealth

HP bar chart
theme_gameboy

Classic Gamyboy inspired ggplot theme
theme_gba

Gamyboy Advanced inspired ggplot theme
theme_rocket

Theme Rocket
theme_status

Health bar theme
theme_instinct

Theme Instinct
theme_mystic

Theme Mystic
theme_valor

Theme Valor
Rokemon

Rokemon
annotate_pogo

Pokemon Go Team Logos
import_pokefont

Import Pokefonts