Pokémon is an electronic game series from Nintendo that debuted in Japan in February 1996. The franchise later became wildly popular after the Game Boy’s version of the game has been produced. The core game itself is based around building a small team of monsters to battle other monsters in a quest to become the best. Many Pokémon games have been created with this same principle along with its most recent title which is Pokémon GO! Also, Pikachu, a yellow mouselike creature, is the undisputed face of Pokémon and helped the series become a worldwide phenomenon.



Pokémon are divided into types, such as and , each with different strengths. Battles between them can be likened to the simple hand game rock-paper-scissors. For example, to gain an advantage over a Pokémon, a player might substitute a Pokémon to deal more damage. Moreover, for the Pokémon to grow stronger and gain new abilities, they have to get more experience by beating other monsters.

In this project, we will try to re-cluster the Pokémon but not based on their actual types, but with their base stats. But before that, we are going to do some Exploratory Data Analysis to understand more about our Pokémon dataset.


1. DATASET

1.1 Description

The Pokémon dataset that we’re using is from Kaggle which includes 721 Pokémon, including their:

  • Name: Name of each Pokémon.
  • Type 1: Each Pokémon has a type, this determines weakness/resistance to attacks.
  • Type 2: Some Pokémon are dual type and have 2.
  • Total: Sum of all stats that come after this, a general guide to how strong a Pokémon is.
  • HP: Hit points, or health, defines how much damage a Pokémon can withstand before fainting.
  • Attack: the Base modifier for normal attacks. (eg. Scratch, Punch)
  • Defense: the Base damage resistance against normal attacks.
  • SP Atk: Special attack, the Base modifier for special attacks. (e.g. fire blast, bubble beam)
  • SP Def: the Base damage resistance against special attacks.
  • Speed: Determines which Pokémon attacks first each round.


1.2 Table Preview

pokemon <- read.csv("Pokemon.csv")
rmarkdown::paged_table(pokemon)


1.3 Data Wrangling

  • Check the data types
glimpse(pokemon)
## Rows: 800
## Columns: 13
## $ X.         <int> 1, 2, 3, 3, 4, 5, 6, 6, 6, 7, 8, 9, 9, 10, 11, 12, 13, 14, …
## $ Name       <chr> "Bulbasaur", "Ivysaur", "Venusaur", "VenusaurMega Venusaur"…
## $ Type.1     <chr> "Grass", "Grass", "Grass", "Grass", "Fire", "Fire", "Fire",…
## $ Type.2     <chr> "Poison", "Poison", "Poison", "Poison", "", "", "Flying", "…
## $ Total      <int> 318, 405, 525, 625, 309, 405, 534, 634, 634, 314, 405, 530,…
## $ HP         <int> 45, 60, 80, 80, 39, 58, 78, 78, 78, 44, 59, 79, 79, 45, 50,…
## $ Attack     <int> 49, 62, 82, 100, 52, 64, 84, 130, 104, 48, 63, 83, 103, 30,…
## $ Defense    <int> 49, 63, 83, 123, 43, 58, 78, 111, 78, 65, 80, 100, 120, 35,…
## $ Sp..Atk    <int> 65, 80, 100, 122, 60, 80, 109, 130, 159, 50, 65, 85, 135, 2…
## $ Sp..Def    <int> 65, 80, 100, 120, 50, 65, 85, 85, 115, 64, 80, 105, 115, 20…
## $ Speed      <int> 45, 60, 80, 80, 65, 80, 100, 100, 100, 43, 58, 78, 78, 45, …
## $ Generation <int> 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,…
## $ Legendary  <chr> "False", "False", "False", "False", "False", "False", "Fals…
  • Check the missing values
colSums(is.na(pokemon))
##         X.       Name     Type.1     Type.2      Total         HP     Attack 
##          0          0          0          0          0          0          0 
##    Defense    Sp..Atk    Sp..Def      Speed Generation  Legendary 
##          0          0          0          0          0          0

Based on the result above, there are no missing values recorded. However, if we look at our glimpse data, there are values with “” which indicates that’s not all Pokémon are dual types. To avoid some confusion, we are going to remove the Secondary Type while only using the Initial Type instead. (or Type.1)

#remove Type.2 from our dataset
pokemon <- pokemon %>% 
  select(-Type.2 )

Also, we want to levels our Characters data types other than the name.

pokemon <- pokemon %>% 
  mutate(Legendary = as.factor(Legendary),
         Type.1 = as.factor(Type.1),
         Generation = as.factor(Generation)) %>% 
  rename(ATK = Attack,
         DEF = Defense,
         SPD = Speed,
         SP_ATK = 'Sp..Atk',
         SP_DEF = 'Sp..Def')


2. EXPLORATORY DATA ANALYSIS

Exploratory Data Analysis (EDA) involves using graphics and visualizations to explore and analyze a data set. The goal is to explore, investigate, and learn the data variables within our dataset. First thing first, we will be analyzing the Pearson Correlation between all of our variables.

poke_num <- pokemon %>% 
  select(Total, HP, ATK, DEF, SP_ATK, SP_DEF, SPD)

cormat <- round(cor(poke_num),2)

get_lower_tri<-function(cormat){
  cormat[upper.tri(cormat)] <- NA
  return(cormat)
  }

get_upper_tri <- function(cormat){
  cormat[lower.tri(cormat)]<- NA
  return(cormat)
}

lower_tri <- get_lower_tri(cormat)

poke_cor_melt <- reshape2::melt(lower_tri, na.rm = TRUE)
poke_cor_melt <- poke_cor_melt %>% 
  mutate(label = glue("{Var1} ~ {Var2}"))

plotcor <- ggplot(poke_cor_melt,
                  aes(Var1, Var2, text = label)) +
  geom_tile(aes(fill = value)) +
  geom_text(aes(label = round(value, 1)), 
            size = 3, 
            color = "Black") + 
  scale_fill_gradientn(colors = c("#FFCC03","White","#FFCC03"),
                       values = rescale(c(-1,0,1)),
                       limits = c(-1,1)) +
  labs(x = NULL,
      y = NULL,
      fill = "Pearson Corr:") +
  theme(plot.background = element_rect(fill = "Black", 
                                       color = "Black"),
        panel.background = element_rect(fill = "Black"),
        panel.grid = element_line(colour = "Black"),
        panel.grid.major.x = element_line(colour = "Black"),
        panel.grid.minor.x = element_line(colour = "Black"),
        legend.position = "none",
        axis.text.x = element_text(color = "#FFF3DC", 
                                   family = "Rockwell",
                                   size = 8,
                                   angle = 45, 
                                   vjust = 1, 
                                   hjust = 1),
        axis.text.y = element_blank(),
        axis.ticks = element_blank()) +
        guides(fill = guide_colorbar(barwidth = 7, 
                                     barheight = 1,
                                     title.position = "top", 
                                     title.hjust = 0.5))

ggplotly(plotcor, 
         tooltip = "text") %>% 
  layout(hoverlabel = list( bgcolor = "Black",
                            font = list(
                                        color = "#1DC9C8",
                                        family = "Rockwell",
                                        size = 14,
                                        face = "bold")))

Insights that we can take from the plot above are:


POKEMON TYPE DISTRIBUTIONS

pokelabel <- pokemon %>% 
  select(Type.1) %>% 
  group_by(Type.1) %>% 
  summarise(count = n()) %>% 
  arrange(desc(count)) %>% 
  rename(Type = "Type.1",
         Count = count) %>% 
  mutate(possition = seq(1:n())) %>% 
  group_by(Type, Count)

# Alignment to the center of the bars: substract 0.5 to center
angle <- 90 - 360 * (pokelabel$possition -0.5)/nrow(pokelabel) 

# Labels alignment
pokelabel$hjust <- if_else(angle < -90, 1, 0)

# flip angle BY to make them readable
pokelabel$angle <- if_else(angle < -90, angle + 180, angle)

poketype <- pokelabel %>% 
  select(Type, Count) %>% 
  ungroup()

typeplot <- poketype %>% 
  ggplot(aes(x = fct_reorder(Type, Count, .desc = TRUE), 
             y = Count,
             fill = Type)) +
  # Create the Bar, color the border using "color".
  geom_bar(stat = "identity",
           order = poketype$Type,
           color = c("#86a8fc", "#ca98a7", "#27cb4f", "#3b9950", "#f81c91", "#fd4c5a", 
                     "#fbfb72", "#8b3e21", "#61cad9", "#906790", "#6e491f", "#5a5979", 
                     "#9b69d9", "#ef6138", "#42bd94", "#d8f0fa", "#ea1369", "#93b2c7"),
           size = 0.5) +
  # -20 is to store our image in the center.
  scale_y_continuous(limits = c(-20, 120)) +
  # place our image in -20 yAxis.
  geom_image(mapping = aes(y= -20, 
                           x = 1, 
                           image = "Assets/goyangpokebol.png"), 
             size=0.118) +
  # Make our plot circle
  coord_polar(start = 0) +
  # Labelling using angle that we created above.
  # Type Label
  geom_text(data = pokelabel, 
            aes(x = possition, 
                y = ifelse(Type == "Flying", Count - (Count*0.01), #Special Condition for Flying
                           Count + if_else(Count < 44, - Count*0.8, - Count*0.9)), 
                label = Type, 
                hjust = ifelse(Type == "Flying", hjust + 0.1, hjust)), 
            color = ifelse(pokelabel$Type == "Flying", "#93b2c7", "White"), 
            family = "Bangers", 
            fontface = "plain", 
            size = 10, 
            angle = pokelabel$angle, #use our angle
            inherit.aes = FALSE) +
  # Count Label
  geom_text(data = pokelabel,
            aes(x = possition,
                y = ifelse(Type == "Flying", Count - (Count*0.8), #Special Condition for Flying
                           Count + if_else(Count < 44, - Count*0.000001, - Count*0.4)),
                label = Count, 
                hjust = ifelse(Type == "Dragon", hjust - 0.3, 
                               ifelse(Count <= 32 & Type != "Flying", hjust + 0.4, hjust))
                ),
            #coloring our label
            color = ifelse(pokelabel$Type == "Flying", "White", 
                           c("#86a8fc", "#ca98a7", "#27cb4f", "#3b9950", "#f81c91", "#fd4c5a", 
                             "#fbfb72", "#8b3e21", "#61cad9", "#906790", "#6e491f", "#5a5979", 
                             "#9b69d9", "#ef6138", "#42bd94", "#d8f0fa", "#ea1369", "#93b2c7")),
            family = "Bangers", 
            fontface = "plain", 
            alpha = 0.8, 
            size = 9, 
            angle = pokelabel$angle, #use our angle
            inherit.aes = F) +
  # Make the bar color match with our Type label.
  scale_fill_manual(values=c("#1552e2", "#75515b", "#147b3d", "#1b4c27", "#a42a6c", "#ab1f23",
                             "#e3e32b", "#48180b", "#448b95", "#33336b", "#a9702c", "#040706",
                             "#5e2d88", "#994025", "#5f756d", "#86d2f5", "#951a44", "#4a677d"),
                    breaks=c("Water","Normal","Grass","Bug","Psychic","Fire",
                             "Electric","Rock","Dragon","Ghost","Ground","Dark",
                             "Poison","Fighting","Steel","Ice","Fairy","Flying")) +
  labs(x = NULL,
       y = NULL) +
  theme_minimal() +
  theme(
    # Remove Legend
    legend.position = "none",
    # Remove Grid
    panel.grid = element_line(colour = "Black"),
    panel.grid.major.x = element_line(colour ="Black"),
    panel.grid.minor.x = element_line(colour ="Black"),
    # Background
    plot.background = element_rect(fill = "Black", color = "Black"),
    panel.background = element_rect(fill = "Black"),
    axis.text.x=element_text(color="Black"),
    axis.text.y=element_text(color="Black"),
    plot.margin = margin(t = -2, r = -6, b = -6, l = -6, unit = "cm")
  )

# Save to our assets
ggsave("Assets/pokemontypebar.png", typeplot, height=4, width=6)

# Call it again using knitr
knitr::include_graphics("Assets/pokemontypebar.png")

Insights that we can take from the plot above are:

  • type Pokémon is the most common Pokémon available.

  • while type Pokémon is the rarest Pokémon available.


TOTAL POWER DISTRIBUTIONS

# Our custom label
img_bug <- magick::image_read("Assets/bug.png")
img_dark <- magick::image_read("Assets/dark.png")
img_dragon <- magick::image_read("Assets/dragon.png")
img_electric <- magick::image_read("Assets/electric.png")
img_fairy <- magick::image_read("Assets/fairy.png")
img_fighting <- magick::image_read("Assets/fighting.png")
img_fire <- magick::image_read("Assets/fire.png")
img_flying <- magick::image_read("Assets/flying.png")
img_ghost <- magick::image_read("Assets/ghost.png")
img_grass <- magick::image_read("Assets/grass.png")
img_ground <- magick::image_read("Assets/ground.png")
img_ice <- magick::image_read("Assets/ice.png")
img_normal <- magick::image_read("Assets/normal.png")
img_poison <- magick::image_read("Assets/poison.png")
img_psychic <- magick::image_read("Assets/psychic.png")
img_rock <- magick::image_read("Assets/rock.png")
img_steel <- magick::image_read("Assets/steel.png")
img_water <- magick::image_read("Assets/water.png")

distplot <- ggplot(pokemon, aes(x = Total, y = Type.1, fill = Type.1, col = Type.1)) +
  # Density Plot
  geom_density_ridges(scale = 2, 
                      rel_min_height = 0.01,
                      quantile_lines=TRUE, 
                      scale=0.85, 
                      quantiles=2, 
                      alpha = 0.7,
                      linetype = "dashed",
                      size = 0.5) +
  # Manually Colorred
  scale_fill_cyclical(values = c("#1b4c27", "#040706", "#448b95", "#e3e32b", "#951a44", "#994025",
                                 "#ab1f23", "#4a677d", "#33336b", "#147b3d", "#a9702c", "#86d2f5",
                                 "#75515b", "#5e2d88", "#a42a6c", "#48180b", "#5f756d", "#1552e2"),
                      guide = "none") +
  scale_color_cyclical(values = c("#3b9950", "#5a5979", "#61cad9", "#fbfb72", "#ea1369", "#ef6138",
                                 "#fd4c5a", "#93b2c7", "#906790", "#27cb4f", "#6e491f", "#d8f0fa",
                                 "#ca98a7", "#9b69d9", "#f81c91", "#8b3e21", "#42bd94", "#86a8fc"),
                      guide = "none") +
  scale_x_continuous(breaks = seq(from = 50, to = 900, by = 50),
                     position = "top") +
  # Custom image label and their placements
  annotation_custom(rasterGrob(image = img_bug,  
                               width = 0.05, 
                               x = 330/800,
                               y = 0.5/10)) +
  annotation_custom(rasterGrob(image = img_dark,
                               width = 0.06, 
                               x = 388/800,
                               y = 1.05/10)) +
  annotation_custom(rasterGrob(image = img_dragon,
                               width = 0.08, 
                               x = 500/800,
                               y = 1.57/10)) +
  annotation_custom(rasterGrob(image = img_electric,
                               width = 0.09, 
                               x = 400/800,
                               y = 2.10/10)) +
  annotation_custom(rasterGrob(image = img_fairy,
                               width = 0.07, 
                               x = 340/800,
                               y = 2.63/10)) +
  annotation_custom(rasterGrob(image = img_fighting,
                               width = 0.1, 
                               x = 379/800,
                               y = 3.18/10)) +
  annotation_custom(rasterGrob(image = img_fire,
                               width = 0.06, 
                               x = 400/800,
                               y = 3.9/10)) +
  annotation_custom(rasterGrob(image = img_flying,
                               width = 0.07, 
                               x = 464/800,
                               y = 4.23/10)) +
  annotation_custom(rasterGrob(image = img_ghost,
                               width = 0.07, 
                               x = 388/800,
                               y = 4.76/10)) +
  annotation_custom(rasterGrob(image = img_grass,
                               width = 0.07, 
                               x = 360/800,
                               y = 5.30/10)) +
  annotation_custom(rasterGrob(image = img_ground,
                               width = 0.09, 
                               x = 370/800,
                               y = 5.85/10)) +
  annotation_custom(rasterGrob(image = img_ice,
                               width = 0.05, 
                               x = 390/800,
                               y = 6.36/10)) +
  annotation_custom(rasterGrob(image = img_normal,
                               width = 0.08, 
                               x = 345/800,
                               y = 6.89/10)) +
  annotation_custom(rasterGrob(image = img_poison,
                               width = 0.08, 
                               x = 339/800,
                               y = 7.42/10)) +
  annotation_custom(rasterGrob(image = img_psychic,
                               width = 0.09, 
                               x = 410/800,
                               y = 8.12/10)) +
  annotation_custom(rasterGrob(image = img_rock,
                               width = 0.06, 
                               x = 390/800,
                               y = 8.44/10)) +
  annotation_custom(rasterGrob(image = img_steel,
                               width = 0.065, 
                               x = 415/800,
                               y = 9.05/10)) +
  annotation_custom(rasterGrob(image = img_water,
                               width = 0.075, 
                               x = 379/800,
                               y = 9.60/10)) +
  labs(x = NULL,
       y = NULL) +
  theme_minimal() +
  theme(
    # Remove Grid
    panel.grid = element_line(colour = "Black"),
    panel.grid.major.x = element_line(colour ="#5C5C5C",
                                      size = 0.1,
                                      linetype = "dashed"),
    panel.grid.minor.x = element_line(colour ="Black"),
    # Background
    plot.background = element_rect(fill = "Black", color = "Black"),
    panel.background = element_rect(fill = "Black"),
    axis.text.x=element_text(color="White",
                             family = "Bangers",
                             size = 22),
    axis.text.y=element_text(color="Black"),
    #Remove blank space on the top, right, bottom and left.
    plot.margin = margin(t = 0.2, r = -0.8, b = -0.83, l = -1, unit = "cm")
  )

# Save to our assets
ggsave("Assets/pokemontypedist.png", distplot, height=10, width=8)

# Call it again using knitr
knitr::include_graphics("Assets/pokemontypedist.png")

Insights that we can take from the plot above are:

  • Based on where the lines end, and types have the strongest Pokémon available. Also, type has the weakest Pokémon available.

  • Based on the median lines, type Pokémon also has the highest Power distribution. However, this might be because there are fewer Pokémon rather than Pokémon.


SPECIAL STATS DISTRIBUTION

In this scatter plot, the circles size are based on the Pokémon Total Power. The bigger the circle, the bigger their Total Power.

# ECHARTS
pokebug <- pokemon %>% 
  filter(Type.1 == "Bug")

pokebug %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, #scale size by Total
            bind = Name, #Add the Pokemon name for the tooltip later
            legend = F) %>%
  #custom theme can be created on https://echarts.apache.org/en/theme-builder.html
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           #Title
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           #Ticks
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           #Rotate
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  #Recolor the circle
  e_color(c("#3b9950","#1b4c27")) %>% 
  #Custom tooltip
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#1b4c27",
            #Custom tooltip
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#3b9950"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#3b9950;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokedark <- pokemon %>% 
  filter(Type.1 == "Dark")

pokedark %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#5a5979","#040706")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#040706",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#5a5979"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#5a5979;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokedragon <- pokemon %>% 
  filter(Type.1 == "Dragon")

pokedragon %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#61cad9","#448b95")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#448b95",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#61cad9"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#61cad9;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokeelectric <- pokemon %>% 
  filter(Type.1 == "Electric")

pokeelectric %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#fbfb72","#e3e32b")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#e3e32b",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#fbfb72"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#fbfb72;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokefairy <- pokemon %>% 
  filter(Type.1 == "Fairy")

pokefairy %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#ea1369","#951a44")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#951a44",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#ea1369"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#ea1369;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokefighting <- pokemon %>% 
  filter(Type.1 == "Fighting")

pokefighting %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#ef6138","#994025")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#994025",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#ef6138"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#ef6138;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokefire <- pokemon %>% 
  filter(Type.1 == "Fire")

pokefire %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#fd4c5a","#ab1f23")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#ab1f23",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#fd4c5a"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#fd4c5a;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokeflying <- pokemon %>% 
  filter(Type.1 == "Flying")

pokeflying %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#93b2c7","#4a677d")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#4a677d",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#93b2c7"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#93b2c7;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokeghost <- pokemon %>% 
  filter(Type.1 == "Ghost")

pokeghost %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#906790","#33336b")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#33336b",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#906790"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#906790;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokegrass <- pokemon %>% 
  filter(Type.1 == "Grass")

pokegrass %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#27cb4f","#147b3d")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#147b3d",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#27cb4f"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#27cb4f;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokeground <- pokemon %>% 
  filter(Type.1 == "Ground")

pokeground %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#6e491f","#a9702c")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#a9702c",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#6e491f"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#6e491f;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokeice <- pokemon %>% 
  filter(Type.1 == "Ice")

pokeice %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#d8f0fa","#86d2f5")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#86d2f5",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#d8f0fa"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#d8f0fa;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokenormal <- pokemon %>% 
  filter(Type.1 == "Normal")

pokenormal %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#ca98a7","#75515b")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#75515b",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#ca98a7"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#ca98a7;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokepoison <- pokemon %>% 
  filter(Type.1 == "Poison")

pokepoison %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#9b69d9","#5e2d88")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#5e2d88",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#9b69d9"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#9b69d9;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokepsychic <- pokemon %>% 
  filter(Type.1 == "Psychic")

pokepsychic %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#f81c91","#a42a6c")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#a42a6c",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#f81c91"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#f81c91;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokerock <- pokemon %>% 
  filter(Type.1 == "Rock")

pokerock %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#8b3e21","#48180b")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#48180b",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#8b3e21"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#8b3e21;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokesteel <- pokemon %>% 
  filter(Type.1 == "Steel")

pokesteel %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#42bd94","#5f756d")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#5f756d",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#42bd94"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#42bd94;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))


pokewater <- pokemon %>% 
  filter(Type.1 == "Water")

pokewater %>% 
  e_charts(SP_DEF) %>% 
  e_scatter(SP_ATK, 
            Total, 
            bind = Name,
            legend = F) %>%
  e_theme_custom("pokeRG.json") %>% 
  e_x_axis(name = "Special DEF",
           nameTextStyle = list(
             color = "#1DC9C8",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold"),
           nameRotate = 90
           ) %>% 
  e_y_axis(name = "Special ATK",
           nameTextStyle = list(
             color = "#FFCC03",
             fontFamily = "Rockwell",
             fontSize = 14,
             fontWeight = "bold"
             ),
           axisLabel = list(
             color = "White",
             fontFamily = "Rockwell",
             fontSize = 12,
             fontWeight = "bold")
           ) %>%
  e_color(c("#86a8fc","#1552e2")) %>% 
  e_tooltip(axis = "trigger",
            showDelay = 0,
            borderColor = "#1552e2",
            axisPointer = list(
              type = "cross",
              label = list(
                backgroundColor = "Black",
                fontFamily = "Rockwell",
                color = "#86a8fc"
              ),
              crossStyle = list(
                color = "White"
              )),
              formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:White;'>Pokemon:</strong> <strong style='color:#86a8fc;'>${params.name}</strong>
                                                    <br/><strong style='color:#1DC9C8;'>Special Defense:</strong> ${params.value[0]}
                                                    <br/><strong style='color:#FFCC03;'>Special Attack:</strong> ${params.value[1]}`
                                        }  "
                                          ))



POWER OF THE GENERATIONS

gen_power <- pokemon %>% 
  select(Generation, Total)
dataMedian <- summarise(group_by(gen_power, Generation), rating_med = median(Total))
dataMedian$rating_med <- round(dataMedian$rating_med,2)

#Plot Code
ggplot(gen_power,
       aes(Generation, Total, col = Generation))+
  # ggfx for neon effect
  with_bloom(geom_boxplot(fill = "Black"),
             sigma = 15,
             strength = 2) +
  # median text
  geom_text(data = dataMedian, 
            aes(Generation, rating_med, label = rating_med),
            family = "Bangers",
            position = position_dodge(width = 0.8), 
            size = 8, 
            vjust = -0.5)+
  scale_color_manual(breaks = c("1", "2", "3", "4", "5", "6"),
                     values = c("White","#FDF202","#EF3524","#FF003C","#D039DD", "#00F0FF")) +
  scale_fill_manual(values = c("Black","Black","Black","Black","Black")) +
  scale_x_discrete(limits = c("1", "2", "3", "4", "5", "6"))+
  labs(x= "Generation",
       y= "Power",
       col = "Generation:")+
  theme(legend.position = "none",
        plot.background = element_rect(fill = "Black", 
                                       color = "Black"),
        panel.background = element_rect(fill = "Black"),
        panel.grid = element_line(colour = "Black"),
        panel.grid.major.x = element_line(colour = "Black"),
        panel.grid.minor.x = element_line(colour = "Black"),
        axis.title.x = element_text(colour = "#1DC9C8",
                                    family = "Bangers",
                                    face = "bold",
                                    size = 22),
        axis.title.y = element_text(colour = "#FFCC03",
                                    family = "Bangers",
                                    face = "bold",
                                    size = 22),
        axis.text.x=element_text(color = "White",
                                 family = "Bangers", 
                                 face = "bold",
                                 size = 18),
        axis.text.y=element_text(color = "White", 
                                 face = "bold", 
                                 family = "Bangers",
                                 size = 18))

Insights that we can take from the plot above are:

  • All generation has a similar Total Power distribution.

  • Median lines show that Generation 4 Pokémon is the strongest Generation.

  • However, the strongest Pokémon available is from Generation 1. (see the outlier)

  • Generation 3 Pokémon has the most diverse Power ratings based on its box’s height.


TOP 3 POKEMON

These are the Basic Stats for Top 3 Pokémon in each type based on their Total Power. These Basic Stats are scaled to 10-100.

top3bug <- c("PinsirMega Pinsir",
             "ScizorMega Scizor",
             "HeracrossMega Heracross")

#top3bug dataframe
pokebug <- pokemon %>% 
  filter(Name %in% top3bug) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"), #to call our image later
         Name = case_when(
           Name %in% top3bug[1] ~ "Pinsir",
           Name %in% top3bug[2] ~ "Scizor",
           Name %in% top3bug[3] ~ "Heracross"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

#create dataframe for custom labels and line segments (for axis)
labels <- data.frame(
  y = c(25,50,75,100),
  x = rep(0.25,4),
  char = rep("Venusaur",4))

# for the segment lines
segments <- data.frame(
  x1=rep(0.5,5),
  x2=rep(4.5,5), 
  y1=c(0,25,50,75,100), 
  y2=c(0,25,50,75,100))


# Plotting
plotbug <- ggplot(pokebug, 
                  aes(x = Attribute, 
                      y = Stat, 
                      fill = Attribute,
                      label = Attribute)) +
  #create y axis text (+30), so we can place it on top of the bar
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with character icon, -70 to place it in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curved polar accommodates text
  coord_curvedpolar() +
  #create line segments to represent panel grid lines. 
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#3b9950",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel grid lines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, #blank zone to place our number label 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  #Manual coloring
  scale_fill_manual(values=c("#1b4c27", "#1b4c27", "#1b4c27", "#1b4c27")) +
  #-70 for image, +130 for our artificial axis (STR, DEF, HP, ATK)
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,
                           b=5,
                           l=10,
                           r=10),
        axis.text=element_blank(),
        # For the pokemon name
        strip.text=element_text(face="bold", 
                                color="#3b9950", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3bug.png", plotbug, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3bug.png")


top3dark <- c("Yveltal",
              "HoundoomMega Houndoom",
              "Darkrai")

#top3bug dataframe
pokedark <- pokemon %>% 
  filter(Name %in% top3dark) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3dark[1] ~ "Yveltal",
           Name %in% top3dark[2] ~ "Houndoom",
           Name %in% top3dark[3] ~ "Darkrai"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotdark <- ggplot(pokedark, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#5a5979",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#232323", "#232323", "#232323", "#232323")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#5a5979", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3dark.png", plotdark, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3dark.png")


top3dragon <- c("RayquazaMega Rayquaza",
                "SalamenceMega Salamence",
                "LatiasMega Latias")

#top3bug dataframe
pokedragon <- pokemon %>% 
  filter(Name %in% top3dragon) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3dragon[1] ~ "Rayquaza",
           Name %in% top3dragon[2] ~ "Salamence",
           Name %in% top3dragon[3] ~ "Latias"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotdragon <- ggplot(pokedragon, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#61cad9",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#448b95", "#448b95", "#448b95", "#448b95")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#61cad9", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3dragon.png", plotdragon, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3dragon.png")


top3electric <- c("AmpharosMega Ampharos",
                  "Zapdos",
                  "Raikou")

#top3bug dataframe
pokeelectric <- pokemon %>% 
  filter(Name %in% top3electric) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3electric[1] ~ "Ampharos",
           Name %in% top3electric[2] ~ "Zapdos",
           Name %in% top3electric[3] ~ "Raikou"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotelectric <- ggplot(pokeelectric, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#fbfb72",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#e3e32b", "#e3e32b", "#e3e32b", "#e3e32b")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#fbfb72", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3electric.png", plotelectric, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3electric.png")


top3fairy <- c("Xerneas",
               "Florges",
               "Togekiss")

#top3bug dataframe
pokefairy <- pokemon %>% 
  filter(Name %in% top3fairy) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3fairy[1] ~ "Xerneas",
           Name %in% top3fairy[2] ~ "Florges",
           Name %in% top3fairy[3] ~ "Togekiss"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotfairy<- ggplot(pokefairy, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#ea1369",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#951a44", "#951a44", "#951a44", "#951a44")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#ea1369", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3fairy.png", plotfairy, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3fairy.png")


top3fighting <- c("LucarioMega Lucario",
                  "MedichamMega Medicham",
                  "Mienshao")

#top3bug dataframe
pokefighting <- pokemon %>% 
  filter(Name %in% top3fighting) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3fighting[1] ~ "Lucario",
           Name %in% top3fighting[2] ~ "Medicham",
           Name %in% top3fighting[3] ~ "Mienshao"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotfighting<- ggplot(pokefighting, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#ef6138",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#994025", "#994025", "#994025", "#994025")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#ef6138", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3fighting.png", plotfighting, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3fighting.png")


top3fire <- c("Ho-oh",
              "CharizardMega Charizard X",
              "BlazikenMega Blaziken")

#top3bug dataframe
pokefire <- pokemon %>% 
  filter(Name %in% top3fire) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3fire[1] ~ "Ho-oh",
           Name %in% top3fire[2] ~ "Charizard X",
           Name %in% top3fire[3] ~ "Blaziken"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotfire<- ggplot(pokefire, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#fd4c5a",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#ab1f23", "#ab1f23", "#ab1f23", "#ab1f23")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#fd4c5a", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3fire.png", plotfire, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3fire.png")


top3flying <- c("TornadusIncarnate Forme",
                "Noivern",
                "Noibat")

#top3bug dataframe
pokeflying <- pokemon %>% 
  filter(Name %in% top3flying) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3flying[1] ~ "Tornadus",
           Name %in% top3flying[2] ~ "Noivern",
           Name %in% top3flying[3] ~ "Noibat"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotflying<- ggplot(pokeflying, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#93b2c7",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#4a677d", "#4a677d", "#4a677d", "#4a677d")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#93b2c7", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3flying.png", plotflying, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3flying.png")


top3ghost <- c("GiratinaAltered Forme",
               "GengarMega Gengar",
               "BanetteMega Banette")

#top3bug dataframe
pokeghost <- pokemon %>% 
  filter(Name %in% top3ghost) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3ghost[1] ~ "Giratina",
           Name %in% top3ghost[2] ~ "Gengar",
           Name %in% top3ghost[3] ~ "Banette"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotghost<- ggplot(pokeghost, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#906790",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#33336b", "#33336b", "#33336b", "#33336b")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#906790", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3ghost.png", plotghost, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3ghost.png")


top3grass <- c("SceptileMega Sceptile",
               "VenusaurMega Venusaur",
               "ShayminLand Forme")

#top3bug dataframe
pokegrass <- pokemon %>% 
  filter(Name %in% top3grass) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3grass[1] ~ "Sceptile",
           Name %in% top3grass[2] ~ "Venusaur",
           Name %in% top3grass[3] ~ "Shaymin"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotgrass<- ggplot(pokegrass, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#27cb4f",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#147b3d", "#147b3d", "#147b3d", "#147b3d")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#27cb4f", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3grass.png", plotgrass, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3grass.png")


top3ground <- c("GroudonPrimal Groudon",
                "LandorusIncarnate Forme",
                "Rhyperior")

#top3bug dataframe
pokeground <- pokemon %>% 
  filter(Name %in% top3ground) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3ground[1] ~ "Groudon",
           Name %in% top3ground[2] ~ "Landorus",
           Name %in% top3ground[3] ~ "Rhyperior"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotground<- ggplot(pokeground, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#6e491f",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#a9702c", "#a9702c", "#a9702c", "#a9702c")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#6e491f", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3ground.png", plotground, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3ground.png")


top3ice <- c("Articuno",
             "GlalieMega Glalie",
             "Regice")

#top3bug dataframe
pokeice <- pokemon %>% 
  filter(Name %in% top3ice) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3ice[1] ~ "Articuno",
           Name %in% top3ice[2] ~ "Glalie",
           Name %in% top3ice[3] ~ "Regice"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotice<- ggplot(pokeice, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#d8f0fa",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#86d2f5", "#86d2f5", "#86d2f5", "#86d2f5")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#d8f0fa", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3ice.png", plotice, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3ice.png")


top3normal <- c("Arceus",
                "Slaking",
                "Regigigas")

#top3bug dataframe
pokenormal <- pokemon %>% 
  filter(Name %in% top3normal) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3normal[1] ~ "Arceus",
           Name %in% top3normal[2] ~ "Slaking",
           Name %in% top3normal[3] ~ "Regigigas"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotnormal<- ggplot(pokenormal, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#ca98a7",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#75515b", "#75515b", "#75515b", "#75515b")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#ca98a7", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3normal.png", plotnormal, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3normal.png")


top3poison <- c("Crobat",
                "Nidoqueen",
                "Nidoking")

#top3bug dataframe
pokepoison <- pokemon %>% 
  filter(Name %in% top3poison) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3poison[1] ~ "Crobat",
           Name %in% top3poison[2] ~ "Nidoqueen",
           Name %in% top3poison[3] ~ "Nidoking"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotpoison<- ggplot(pokepoison, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#9b69d9",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#5e2d88", "#5e2d88", "#5e2d88", "#5e2d88")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#9b69d9", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3poison.png", plotpoison, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3poison.png")


top3psychic <- c("MewtwoMega Mewtwo X",
                 "Lugia",
                 "HoopaHoopa Unbound")

#top3bug dataframe
pokepsychic <- pokemon %>% 
  filter(Name %in% top3psychic) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3psychic[1] ~ "Mewtwo X",
           Name %in% top3psychic[2] ~ "Lugia",
           Name %in% top3psychic[3] ~ "Hoopa"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotpsychic<- ggplot(pokepsychic, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#f81c91",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#a42a6c", "#a42a6c", "#a42a6c", "#a42a6c")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#f81c91", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3psychic.png", plotpsychic, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3psychic.png")


top3rock <- c("TyranitarMega Tyranitar",
              "DiancieMega Diancie",
              "AerodactylMega Aerodactyl")

#top3bug dataframe
pokerock <- pokemon %>% 
  filter(Name %in% top3rock) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3rock[1] ~ "Tyranitar",
           Name %in% top3rock[2] ~ "Diancie",
           Name %in% top3rock[3] ~ "Aerodactyl"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotrock<- ggplot(pokerock, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#8b3e21",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#48180b", "#48180b", "#48180b", "#48180b")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#8b3e21", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3rock.png", plotrock, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3rock.png")


top3steel <- c("MetagrossMega Metagross",
               "Dialga",
               "AggronMega Aggron")

#top3bug dataframe
pokesteel<- pokemon %>% 
  filter(Name %in% top3steel) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3steel[1] ~ "Metagross",
           Name %in% top3steel[2] ~ "Dialga",
           Name %in% top3steel[3] ~ "Aggron"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotsteel<- ggplot(pokesteel, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#42bd94",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#5f756d", "#5f756d", "#5f756d", "#5f756d")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#42bd94", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3steel.png", plotsteel, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3steel.png")


top3water <- c("KyogrePrimal Kyogre",
               "Palkia",
               "GyaradosMega Gyarados")

#top3bug dataframe
pokewater<- pokemon %>% 
  filter(Name %in% top3water) %>% 
  select(Name, HP, ATK, DEF, SPD, SP_ATK, SP_DEF) %>% 
  pivot_longer(-c(Name,SP_ATK, SP_DEF), names_to = "Attribute", values_to = "Stat") %>% 
  mutate(image = paste0("Assets/",tolower(str_replace_all(Name, " ","_")),".png"),
         Name = case_when(
           Name %in% top3water[1] ~ "Kyogre",
           Name %in% top3water[2] ~ "Palkia",
           Name %in% top3water[3] ~ "Gyarados"
         ),
         Stat = round(rescale(Stat, to = c(10, 100)),0))

# Plotting
plotwater<- ggplot(pokewater, 
                  aes(x = Attribute, 
                  y = Stat, 
                  fill = Attribute,
                  label = Attribute)) +
  #create y axis text (+30)
  geom_textpath(inherit.aes = FALSE, 
                mapping = aes(x = Attribute, 
                              label = Attribute, 
                              y = 130), 
                fontface = "bold", 
                upright = TRUE, 
                text_only = TRUE, 
                size = 12, 
                color = "#F2F2F2", 
                family = "Russo One") +
  #image with cahracter icon in the center
  geom_image(mapping = aes(y= -70, 
                           x = 1, 
                           image = image), 
             size=0.225) +
  #create curved coordinate system, curvedpolar accomodates text
  coord_curvedpolar() +
  #create linesegments to represent panel gridlines
  geom_segment(inherit.aes=FALSE, 
               data = segments, 
               mapping = aes(x = x1, 
                             xend = x2,
                             y = y1, 
                             yend  = y2), 
               size=0.8, 
               color = "#181818") +
  #bars
  geom_col(color = "#86a8fc",
           size = 1,
           show.legend = FALSE, 
           width=0.9) +
  #text for panel gridlines
  geom_textsegment(inherit.aes = FALSE, 
                   data = labels, 
                   mapping = aes(x = 4.5, 
                                 xend = 4.8, 
                                 y = y, 
                                 yend = y, 
                                 label=y), 
                   color = "#181818", 
                   textcolour = "#F2F2F2", 
                   linewidth=1, 
                   size=10) +
  scale_fill_manual(values=c("#1552e2", "#1552e2", "#1552e2", "#1552e2")) +
  scale_y_continuous(limits=c(-70,130)) +
  #iterate per character
  facet_wrap(~Name, 
             ncol = 3) +
  theme_minimal() +
  theme(text=element_text(family="Cardo", 
                          color="Black"),
        plot.background = element_rect(fill="Black"),
        axis.title=element_text(family="Russo One", 
                                color="Black"),
        panel.grid = element_blank(),
        plot.margin=margin(t=10,b=5,l=10,r=10),
        axis.text=element_blank(),
        strip.text=element_text(face="bold", 
                                color="#86a8fc", 
                                size=100, 
                                family = "Bangers"))

# Save to our assets
ggsave("Assets/top3water.png", plotwater, height=5.83, width=15.5)

# Call it again using knitr
knitr::include_graphics("Assets/top3water.png")


3. CLUSTERING

Clustering refers to the practice of finding meaningful ways to group data (or create subgroups) within a dataset - and the resulting groups are usually called clusters. The objective is to have a number of partitions where the observations that fall into each partition are similar to others in that group, while the partitions are distinctive from one another.


3.1 Data Pre-processing

  • Select only the numerical variables but keep the name of the Pokémon as the row names.
# Name as the rownames
poke_df <- pokemon %>% 
  column_to_rownames(var = "Name")

# Select only the numerical column without Total.
poke_df <- poke_df %>% 
  select(HP, ATK, DEF, SP_ATK, SP_DEF, SPD)

rmarkdown::paged_table(head(poke_df))
  • Check our variable's scales
summary(poke_df)
##        HP              ATK           DEF             SP_ATK      
##  Min.   :  1.00   Min.   :  5   Min.   :  5.00   Min.   : 10.00  
##  1st Qu.: 50.00   1st Qu.: 55   1st Qu.: 50.00   1st Qu.: 49.75  
##  Median : 65.00   Median : 75   Median : 70.00   Median : 65.00  
##  Mean   : 69.26   Mean   : 79   Mean   : 73.84   Mean   : 72.82  
##  3rd Qu.: 80.00   3rd Qu.:100   3rd Qu.: 90.00   3rd Qu.: 95.00  
##  Max.   :255.00   Max.   :190   Max.   :230.00   Max.   :194.00  
##      SP_DEF           SPD        
##  Min.   : 20.0   Min.   :  5.00  
##  1st Qu.: 50.0   1st Qu.: 45.00  
##  Median : 70.0   Median : 65.00  
##  Mean   : 71.9   Mean   : 68.28  
##  3rd Qu.: 90.0   3rd Qu.: 90.00  
##  Max.   :230.0   Max.   :180.00

We can see that all of our variables are still in similar scales and we don’t need to do some scalling.


3.2 Finding Optimum Number of Clusters

Or we can say finding the optimal number of clusters, we seek to minimize the total within-cluster sum of squares (meaning that the distance is minimum between obseration in the same cluster). To find the optimum number of cluster we will use the Elbow Method, Silhouette Method & Gap Statistic.

3.2.1 ELBOW METHOD

To use Elbow Method is to choose the number of cluster in the area of “bend of an elbow”, what we’re looking for is a point where diminishing returns start to kick in (an elbow) and we start to lose substantial gains.

pikachoe <- magick::image_read("Assets/pikachoe.png")

elbowplot <- fviz_nbclust(x = poke_df, 
                          FUNcluster = kmeans,
                          method = "wss",
                          verbose = F) +
  with_outer_glow(geom_line(aes(group = 1), 
                            color = "White",
                            size = 0.5),
                  colour = "#FFCC03", 
                  sigma = 10, 
                  expand = 0.7) + 
  with_outer_glow(geom_point(group = 1, 
                             size = 1, 
                             color = "White"),
                  colour = "#1DC9C8", 
                  sigma = 10, 
                  expand = 0.7) +
  geom_vline(xintercept = 5,
             size = 0.5,
             linetype = "dashed", 
             color = '#1DC9C8') +
  scale_y_continuous(labels = label_number(suffix = " M", scale = 1e-6)) +
  annotate('text', 
           color = "#FFCC03",
           x = 6.2, 
           y = 2350000, 
           label = 'This is our K!',
           family = "Bangers",
           size = 7) +
  annotate(geom = "curve",
           color = "White",
           x = 5.8, 
           y = 2300000, 
           xend = 5.1, 
           yend = 2100000, 
           curvature = 0.1, 
           arrow = arrow(length = unit(0.2, 'cm'))) +
  annotation_custom(rasterGrob(image = pikachoe,
                               width = 0.08, 
                               x = 5.7/10,
                               y = 1700000/4500000)) +
  theme(legend.position = "none",
        plot.background = element_rect(fill = "Black", 
                                       color = "Black"),
        panel.background = element_rect(fill = "Black"),
        panel.grid = element_line(colour = "Black"),
        panel.grid.major.x = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        panel.grid.minor.x = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        panel.grid.major.y = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        axis.title.x = element_text(colour = "#1DC9C8",
                                    family = "Bangers",
                                    face = "bold",
                                    size = 24),
        axis.title.y = element_text(colour = "#FFCC03",
                                    family = "Bangers",
                                    face = "bold",
                                    size = 24),
        axis.text.x=element_text(color = "White",
                                 family = "Bangers", 
                                 face = "bold",
                                 size = 20),
        axis.text.y=element_text(color = "White", 
                                 face = "bold", 
                                 family = "Bangers",
                                 size = 20))

# Save to our assets
ggsave("Assets/elbowplot.png", elbowplot, height=4, width=6)

# Call it again using knitr
knitr::include_graphics("Assets/elbowplot.png")

As demonstrated from our Elbow Method, the plot recommends to use 5 clusters for our dataset. However this is still not enough since the line itself is still vague. We will try to use another method that called Silhouette Method.

3.2.2 SILHOUETTE METHOD

Silhouette Method measures the silhouette coefficient, by calculating the mean intra-cluster distance and the mean nearest-cluster distance for each observations. What we’re looking for is the peak-point which is the cluster with the highest silhouette score.

silhoplot <- fviz_nbclust(x = poke_df, 
                          FUNcluster = kmeans,
                          method = "silhouette",
                          verbose = F) +
  with_outer_glow(geom_line(aes(group = 1), 
                            color = "White",
                            size = 0.5),
                  colour = "#FFCC03", 
                  sigma = 10, 
                  expand = 0.7) + 
  with_outer_glow(geom_point(group = 1, 
                             size = 1, 
                             color = "White"),
                  colour = "#1DC9C8", 
                  sigma = 10, 
                  expand = 0.7) +
  geom_vline(xintercept = 2,
             size = 0.5,
             linetype = "dashed", 
             color = '#1DC9C8') +
  annotate('text', 
           color = "#FFCC03",
           x = 3.3, 
           y = 0.3, 
           label = 'This is our K!',
           family = "Bangers",
           size = 7) +
  annotate(geom = "curve",
           color = "White",
           x = 2.8, 
           y = 0.3, 
           xend = 2.1, 
           yend = 0.29, 
           curvature = 0.1, 
           arrow = arrow(length = unit(0.2, 'cm'))) +
  theme(legend.position = "none",
        plot.background = element_rect(fill = "Black", 
                                       color = "Black"),
        panel.background = element_rect(fill = "Black"),
        panel.grid = element_line(colour = "Black"),
        panel.grid.major.x = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        panel.grid.minor.x = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        panel.grid.major.y = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        axis.title.x = element_text(colour = "#1DC9C8",
                                    family = "Bangers",
                                    face = "bold",
                                    size = 24),
        axis.title.y = element_text(colour = "#FFCC03",
                                    family = "Bangers",
                                    face = "bold",
                                    size = 24),
        axis.text.x=element_text(color = "White",
                                 family = "Bangers", 
                                 face = "bold",
                                 size = 20),
        axis.text.y=element_text(color = "White", 
                                 face = "bold", 
                                 family = "Bangers",
                                 size = 20))

# Save to our assets
ggsave("Assets/silhoplot.png", silhoplot, height=4, width=6)

# Call it again using knitr
knitr::include_graphics("Assets/silhoplot.png")

The Silhouette Method shows that the optimum number of cluster is 2.

Since these 2 methods shows a different number of optimum k, we are going to choose the result from our Elbow Method since every clusters below 3 are considered too few for clustering.


3.2.3 GAP STATISTIC METHOD

The gap statistic compares the total within intra-cluster variation for different values of k with their expected values under null reference distribution of the data. The estimate of the optimal clusters will be value that maximize the gap statistic.

gaplot <- fviz_nbclust(x = poke_df, 
                          FUNcluster = kmeans,
                          method = "gap_stat",
                          verbose = F) +
  with_outer_glow(geom_line(aes(group = 1), 
                            color = "White",
                            size = 0.5),
                  colour = "#FFCC03", 
                  sigma = 10, 
                  expand = 0.7) + 
  with_outer_glow(geom_point(group = 1, 
                             size = 1, 
                             color = "White"),
                  colour = "#1DC9C8", 
                  sigma = 10, 
                  expand = 0.7) +
  geom_vline(xintercept = 2,
             size = 0.5,
             linetype = "dashed", 
             color = '#1DC9C8') +
  annotate('text', 
           color = "#FFCC03",
           x = 3.25, 
           y = 0.940, 
           label = 'This is our K!',
           family = "Bangers",
           size = 7) +
  annotate(geom = "curve",
           color = "White",
           x = 2.8, 
           y = 0.940, 
           xend = 2.1, 
           yend = 0.926, 
           curvature = 0.1, 
           arrow = arrow(length = unit(0.2, 'cm'))) +
  theme(legend.position = "none",
        plot.background = element_rect(fill = "Black", 
                                       color = "Black"),
        panel.background = element_rect(fill = "Black"),
        panel.grid = element_line(colour = "Black"),
        panel.grid.major.x = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        panel.grid.minor.x = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        panel.grid.major.y = element_line(colour = "#5C5C5C",
                                          size = 0.1,
                                          linetype = "dashed"),
        axis.title.x = element_text(colour = "#1DC9C8",
                                    family = "Bangers",
                                    face = "bold",
                                    size = 24),
        axis.title.y = element_text(colour = "#FFCC03",
                                    family = "Bangers",
                                    face = "bold",
                                    size = 24),
        axis.text.x=element_text(color = "White",
                                 family = "Bangers", 
                                 face = "bold",
                                 size = 20),
        axis.text.y=element_text(color = "White", 
                                 face = "bold", 
                                 family = "Bangers",
                                 size = 20))

# Save to our assets
ggsave("Assets/gaplot.png", gaplot, height=4, width=6)

# Call it again using knitr
knitr::include_graphics("Assets/gaplot.png")

Based on the gap statistic method, shows that the optimum number of cluster is 2.

Two out of three methods suggest that k = 2 is the optimum number of clusters. And we are going to use that number for our clustering.


3.3 K-Means Clustering

K-means is a centroid-based clustering algorithm that follows a procedure of classifying a given dataset into a pre-determined number of clusters, denoted as k. Here are the general process of K-means clustering:

  1. Random initialization: Randomly initialize our cluster centers (centroid) and the numbers of our centroid are based on how much our k are set.

  2. Cluster assignment: Assign each observation to the nearest centroid based on its euclidean distance calculation. To do this, we have to make sure that our dataset has the same scale for its variables.

  3. Centroid Update: Moves the centroid to the means point of each cluster.

  4. Repeat the process until the centroids is not moving again.

Now we already have the number of our cluster centers/centroids (which are 2), we will start the process above using kmeans() function.

set.seed(417)
poke_km <- kmeans(poke_df, centers = 2)
poke_km
## K-means clustering with 2 clusters of sizes 374, 426
## 
## Cluster means:
##         HP      ATK      DEF   SP_ATK   SP_DEF      SPD
## 1 54.87968 57.94118 55.49733 52.33155 53.44118 54.04278
## 2 81.88263 97.49061 89.94836 90.80751 88.11033 80.77465
## 
## Clustering vector:
##                 Bulbasaur                   Ivysaur                  Venusaur 
##                         1                         1                         2 
##     VenusaurMega Venusaur                Charmander                Charmeleon 
##                         2                         1                         1 
##                 Charizard CharizardMega Charizard X CharizardMega Charizard Y 
##                         2                         2                         2 
##                  Squirtle                 Wartortle                 Blastoise 
##                         1                         1                         2 
##   BlastoiseMega Blastoise                  Caterpie                   Metapod 
##                         2                         1                         1 
##                Butterfree                    Weedle                    Kakuna 
##                         1                         1                         1 
##                  Beedrill     BeedrillMega Beedrill                    Pidgey 
##                         1                         2                         1 
##                 Pidgeotto                   Pidgeot       PidgeotMega Pidgeot 
##                         1                         2                         2 
##                   Rattata                  Raticate                   Spearow 
##                         1                         1                         1 
##                    Fearow                     Ekans                     Arbok 
##                         2                         1                         2 
##                   Pikachu                    Raichu                 Sandshrew 
##                         1                         2                         1 
##                 Sandslash                  Nidoran♀                  Nidorina 
##                         2                         1                         1 
##                 Nidoqueen                  Nidoran♂                  Nidorino 
##                         2                         1                         1 
##                  Nidoking                  Clefairy                  Clefable 
##                         2                         1                         2 
##                    Vulpix                 Ninetales                Jigglypuff 
##                         1                         2                         1 
##                Wigglytuff                     Zubat                    Golbat 
##                         1                         1                         2 
##                    Oddish                     Gloom                 Vileplume 
##                         1                         1                         2 
##                     Paras                  Parasect                   Venonat 
##                         1                         1                         1 
##                  Venomoth                   Diglett                   Dugtrio 
##                         2                         1                         1 
##                    Meowth                   Persian                   Psyduck 
##                         1                         1                         1 
##                   Golduck                    Mankey                  Primeape 
##                         2                         1                         2 
##                 Growlithe                  Arcanine                   Poliwag 
##                         1                         2                         1 
##                 Poliwhirl                 Poliwrath                      Abra 
##                         1                         2                         1 
##                   Kadabra                  Alakazam     AlakazamMega Alakazam 
##                         1                         2                         2 
##                    Machop                   Machoke                   Machamp 
##                         1                         1                         2 
##                Bellsprout                Weepinbell                Victreebel 
##                         1                         1                         2 
##                 Tentacool                Tentacruel                   Geodude 
##                         1                         2                         1 
##                  Graveler                     Golem                    Ponyta 
##                         1                         2                         1 
##                  Rapidash                  Slowpoke                   Slowbro 
##                         2                         1                         2 
##       SlowbroMega Slowbro                 Magnemite                  Magneton 
##                         2                         1                         2 
##                Farfetch'd                     Doduo                    Dodrio 
##                         1                         1                         2 
##                      Seel                   Dewgong                    Grimer 
##                         1                         2                         1 
##                       Muk                  Shellder                  Cloyster 
##                         2                         1                         2 
##                    Gastly                   Haunter                    Gengar 
##                         1                         1                         2 
##         GengarMega Gengar                      Onix                   Drowzee 
##                         2                         1                         1 
##                     Hypno                    Krabby                   Kingler 
##                         2                         1                         2 
##                   Voltorb                 Electrode                 Exeggcute 
##                         1                         2                         1 
##                 Exeggutor                    Cubone                   Marowak 
##                         2                         1                         2 
##                 Hitmonlee                Hitmonchan                 Lickitung 
##                         2                         2                         1 
##                   Koffing                   Weezing                   Rhyhorn 
##                         1                         2                         1 
##                    Rhydon                   Chansey                   Tangela 
##                         2                         1                         2 
##                Kangaskhan KangaskhanMega Kangaskhan                    Horsea 
##                         2                         2                         1 
##                    Seadra                   Goldeen                   Seaking 
##                         2                         1                         2 
##                    Staryu                   Starmie                  Mr. Mime 
##                         1                         2                         2 
##                   Scyther                      Jynx                Electabuzz 
##                         2                         2                         2 
##                    Magmar                    Pinsir         PinsirMega Pinsir 
##                         2                         2                         2 
##                    Tauros                  Magikarp                  Gyarados 
##                         2                         1                         2 
##     GyaradosMega Gyarados                    Lapras                     Ditto 
##                         2                         2                         1 
##                     Eevee                  Vaporeon                   Jolteon 
##                         1                         2                         2 
##                   Flareon                   Porygon                   Omanyte 
##                         2                         1                         1 
##                   Omastar                    Kabuto                  Kabutops 
##                         2                         1                         2 
##                Aerodactyl AerodactylMega Aerodactyl                   Snorlax 
##                         2                         2                         2 
##                  Articuno                    Zapdos                   Moltres 
##                         2                         2                         2 
##                   Dratini                 Dragonair                 Dragonite 
##                         1                         1                         2 
##                    Mewtwo       MewtwoMega Mewtwo X       MewtwoMega Mewtwo Y 
##                         2                         2                         2 
##                       Mew                 Chikorita                   Bayleef 
##                         2                         1                         1 
##                  Meganium                 Cyndaquil                   Quilava 
##                         2                         1                         1 
##                Typhlosion                  Totodile                  Croconaw 
##                         2                         1                         1 
##                Feraligatr                   Sentret                    Furret 
##                         2                         1                         1 
##                  Hoothoot                   Noctowl                    Ledyba 
##                         1                         2                         1 
##                    Ledian                  Spinarak                   Ariados 
##                         1                         1                         1 
##                    Crobat                  Chinchou                   Lanturn 
##                         2                         1                         2 
##                     Pichu                    Cleffa                 Igglybuff 
##                         1                         1                         1 
##                    Togepi                   Togetic                      Natu 
##                         1                         1                         1 
##                      Xatu                    Mareep                   Flaaffy 
##                         2                         1                         1 
##                  Ampharos     AmpharosMega Ampharos                 Bellossom 
##                         2                         2                         2 
##                    Marill                 Azumarill                 Sudowoodo 
##                         1                         1                         1 
##                  Politoed                    Hoppip                  Skiploom 
##                         2                         1                         1 
##                  Jumpluff                     Aipom                   Sunkern 
##                         2                         1                         1 
##                  Sunflora                     Yanma                    Wooper 
##                         2                         1                         1 
##                  Quagsire                    Espeon                   Umbreon 
##                         2                         2                         2 
##                   Murkrow                  Slowking                Misdreavus 
##                         1                         2                         2 
##                     Unown                 Wobbuffet                 Girafarig 
##                         1                         1                         2 
##                    Pineco                Forretress                 Dunsparce 
##                         1                         2                         1 
##                    Gligar                   Steelix       SteelixMega Steelix 
##                         1                         2                         2 
##                  Snubbull                  Granbull                  Qwilfish 
##                         1                         2                         1 
##                    Scizor         ScizorMega Scizor                   Shuckle 
##                         2                         2                         2 
##                 Heracross   HeracrossMega Heracross                   Sneasel 
##                         2                         2                         1 
##                 Teddiursa                  Ursaring                    Slugma 
##                         1                         2                         1 
##                  Magcargo                    Swinub                 Piloswine 
##                         1                         1                         2 
##                   Corsola                  Remoraid                 Octillery 
##                         1                         1                         2 
##                  Delibird                   Mantine                  Skarmory 
##                         1                         2                         2 
##                  Houndour                  Houndoom     HoundoomMega Houndoom 
##                         1                         2                         2 
##                   Kingdra                    Phanpy                   Donphan 
##                         2                         1                         2 
##                  Porygon2                  Stantler                  Smeargle 
##                         2                         2                         1 
##                   Tyrogue                 Hitmontop                  Smoochum 
##                         1                         2                         1 
##                    Elekid                     Magby                   Miltank 
##                         1                         1                         2 
##                   Blissey                    Raikou                     Entei 
##                         2                         2                         2 
##                   Suicune                  Larvitar                   Pupitar 
##                         2                         1                         1 
##                 Tyranitar   TyranitarMega Tyranitar                     Lugia 
##                         2                         2                         2 
##                     Ho-oh                    Celebi                   Treecko 
##                         2                         2                         1 
##                   Grovyle                  Sceptile     SceptileMega Sceptile 
##                         1                         2                         2 
##                   Torchic                 Combusken                  Blaziken 
##                         1                         1                         2 
##     BlazikenMega Blaziken                    Mudkip                 Marshtomp 
##                         2                         1                         1 
##                  Swampert     SwampertMega Swampert                 Poochyena 
##                         2                         2                         1 
##                 Mightyena                 Zigzagoon                   Linoone 
##                         1                         1                         1 
##                   Wurmple                   Silcoon                 Beautifly 
##                         1                         1                         1 
##                   Cascoon                    Dustox                     Lotad 
##                         1                         1                         1 
##                    Lombre                  Ludicolo                    Seedot 
##                         1                         2                         1 
##                   Nuzleaf                   Shiftry                   Taillow 
##                         1                         2                         1 
##                   Swellow                   Wingull                  Pelipper 
##                         1                         1                         2 
##                     Ralts                    Kirlia                 Gardevoir 
##                         1                         1                         2 
##   GardevoirMega Gardevoir                   Surskit                Masquerain 
##                         2                         1                         1 
##                 Shroomish                   Breloom                   Slakoth 
##                         1                         2                         1 
##                  Vigoroth                   Slaking                   Nincada 
##                         2                         2                         1 
##                   Ninjask                  Shedinja                   Whismur 
##                         2                         1                         1 
##                   Loudred                   Exploud                  Makuhita 
##                         1                         2                         1 
##                  Hariyama                   Azurill                  Nosepass 
##                         2                         1                         1 
##                    Skitty                  Delcatty                   Sableye 
##                         1                         1                         1 
##       SableyeMega Sableye                    Mawile         MawileMega Mawile 
##                         2                         1                         2 
##                      Aron                    Lairon                    Aggron 
##                         1                         2                         2 
##         AggronMega Aggron                  Meditite                  Medicham 
##                         2                         1                         1 
##     MedichamMega Medicham                 Electrike                 Manectric 
##                         2                         1                         2 
##   ManectricMega Manectric                    Plusle                     Minun 
##                         2                         1                         1 
##                   Volbeat                  Illumise                   Roselia 
##                         1                         1                         1 
##                    Gulpin                    Swalot                  Carvanha 
##                         1                         2                         1 
##                  Sharpedo     SharpedoMega Sharpedo                   Wailmer 
##                         2                         2                         1 
##                   Wailord                     Numel                  Camerupt 
##                         2                         1                         2 
##     CameruptMega Camerupt                   Torkoal                    Spoink 
##                         2                         2                         1 
##                   Grumpig                    Spinda                  Trapinch 
##                         2                         1                         1 
##                   Vibrava                    Flygon                    Cacnea 
##                         1                         2                         1 
##                  Cacturne                    Swablu                   Altaria 
##                         2                         1                         2 
##       AltariaMega Altaria                  Zangoose                   Seviper 
##                         2                         2                         2 
##                  Lunatone                   Solrock                  Barboach 
##                         2                         2                         1 
##                  Whiscash                  Corphish                 Crawdaunt 
##                         2                         1                         2 
##                    Baltoy                   Claydol                    Lileep 
##                         1                         2                         1 
##                   Cradily                   Anorith                   Armaldo 
##                         2                         1                         2 
##                    Feebas                   Milotic                  Castform 
##                         1                         2                         1 
##                   Kecleon                   Shuppet                   Banette 
##                         2                         1                         2 
##       BanetteMega Banette                   Duskull                  Dusclops 
##                         2                         1                         2 
##                   Tropius                  Chimecho                     Absol 
##                         2                         1                         2 
##           AbsolMega Absol                    Wynaut                   Snorunt 
##                         2                         1                         1 
##                    Glalie         GlalieMega Glalie                    Spheal 
##                         2                         2                         1 
##                    Sealeo                   Walrein                  Clamperl 
##                         1                         2                         1 
##                   Huntail                  Gorebyss                 Relicanth 
##                         2                         2                         2 
##                   Luvdisc                     Bagon                   Shelgon 
##                         1                         1                         1 
##                 Salamence   SalamenceMega Salamence                    Beldum 
##                         2                         2                         1 
##                    Metang                 Metagross   MetagrossMega Metagross 
##                         1                         2                         2 
##                  Regirock                    Regice                 Registeel 
##                         2                         2                         2 
##                    Latias         LatiasMega Latias                    Latios 
##                         2                         2                         2 
##         LatiosMega Latios                    Kyogre       KyogrePrimal Kyogre 
##                         2                         2                         2 
##                   Groudon     GroudonPrimal Groudon                  Rayquaza 
##                         2                         2                         2 
##     RayquazaMega Rayquaza                   Jirachi        DeoxysNormal Forme 
##                         2                         2                         2 
##        DeoxysAttack Forme       DeoxysDefense Forme         DeoxysSpeed Forme 
##                         2                         2                         2 
##                   Turtwig                    Grotle                  Torterra 
##                         1                         1                         2 
##                  Chimchar                  Monferno                 Infernape 
##                         1                         1                         2 
##                    Piplup                  Prinplup                  Empoleon 
##                         1                         1                         2 
##                    Starly                  Staravia                 Staraptor 
##                         1                         1                         2 
##                    Bidoof                   Bibarel                 Kricketot 
##                         1                         1                         1 
##                Kricketune                     Shinx                     Luxio 
##                         1                         1                         1 
##                    Luxray                     Budew                  Roserade 
##                         2                         1                         2 
##                  Cranidos                 Rampardos                  Shieldon 
##                         1                         2                         1 
##                 Bastiodon                     Burmy       WormadamPlant Cloak 
##                         2                         1                         2 
##       WormadamSandy Cloak       WormadamTrash Cloak                    Mothim 
##                         2                         2                         2 
##                    Combee                 Vespiquen                 Pachirisu 
##                         1                         2                         1 
##                    Buizel                  Floatzel                   Cherubi 
##                         1                         2                         1 
##                   Cherrim                   Shellos                 Gastrodon 
##                         2                         1                         2 
##                   Ambipom                  Drifloon                  Drifblim 
##                         2                         1                         2 
##                   Buneary                   Lopunny       LopunnyMega Lopunny 
##                         1                         2                         2 
##                 Mismagius                 Honchkrow                   Glameow 
##                         2                         2                         1 
##                   Purugly                 Chingling                    Stunky 
##                         2                         1                         1 
##                  Skuntank                   Bronzor                  Bronzong 
##                         2                         1                         2 
##                    Bonsly                  Mime Jr.                   Happiny 
##                         1                         1                         1 
##                    Chatot                 Spiritomb                     Gible 
##                         1                         2                         1 
##                    Gabite                  Garchomp     GarchompMega Garchomp 
##                         1                         2                         2 
##                  Munchlax                     Riolu                   Lucario 
##                         1                         1                         2 
##       LucarioMega Lucario                Hippopotas                 Hippowdon 
##                         2                         1                         2 
##                   Skorupi                   Drapion                  Croagunk 
##                         1                         2                         1 
##                 Toxicroak                 Carnivine                   Finneon 
##                         2                         2                         1 
##                  Lumineon                   Mantyke                    Snover 
##                         2                         1                         1 
##                 Abomasnow   AbomasnowMega Abomasnow                   Weavile 
##                         2                         2                         2 
##                 Magnezone                Lickilicky                 Rhyperior 
##                         2                         2                         2 
##                 Tangrowth                Electivire                 Magmortar 
##                         2                         2                         2 
##                  Togekiss                   Yanmega                   Leafeon 
##                         2                         2                         2 
##                   Glaceon                   Gliscor                 Mamoswine 
##                         2                         2                         2 
##                 Porygon-Z                   Gallade       GalladeMega Gallade 
##                         2                         2                         2 
##                 Probopass                  Dusknoir                  Froslass 
##                         2                         2                         2 
##                     Rotom           RotomHeat Rotom           RotomWash Rotom 
##                         2                         2                         2 
##          RotomFrost Rotom            RotomFan Rotom            RotomMow Rotom 
##                         2                         2                         2 
##                      Uxie                   Mesprit                     Azelf 
##                         2                         2                         2 
##                    Dialga                    Palkia                   Heatran 
##                         2                         2                         2 
##                 Regigigas     GiratinaAltered Forme      GiratinaOrigin Forme 
##                         2                         2                         2 
##                 Cresselia                    Phione                   Manaphy 
##                         2                         2                         2 
##                   Darkrai         ShayminLand Forme          ShayminSky Forme 
##                         2                         2                         2 
##                    Arceus                   Victini                     Snivy 
##                         2                         2                         1 
##                   Servine                 Serperior                     Tepig 
##                         1                         2                         1 
##                   Pignite                    Emboar                  Oshawott 
##                         1                         2                         1 
##                    Dewott                  Samurott                    Patrat 
##                         1                         2                         1 
##                   Watchog                  Lillipup                   Herdier 
##                         1                         1                         1 
##                 Stoutland                  Purrloin                   Liepard 
##                         2                         1                         2 
##                   Pansage                  Simisage                   Pansear 
##                         1                         2                         1 
##                  Simisear                   Panpour                  Simipour 
##                         2                         1                         2 
##                     Munna                  Musharna                    Pidove 
##                         1                         2                         1 
##                 Tranquill                  Unfezant                   Blitzle 
##                         1                         2                         1 
##                 Zebstrika                Roggenrola                   Boldore 
##                         2                         1                         1 
##                  Gigalith                    Woobat                   Swoobat 
##                         2                         1                         1 
##                   Drilbur                 Excadrill                    Audino 
##                         1                         2                         2 
##         AudinoMega Audino                   Timburr                   Gurdurr 
##                         2                         1                         1 
##                Conkeldurr                   Tympole                 Palpitoad 
##                         2                         1                         1 
##                Seismitoad                     Throh                      Sawk 
##                         2                         2                         2 
##                  Sewaddle                  Swadloon                  Leavanny 
##                         1                         1                         2 
##                  Venipede                Whirlipede                 Scolipede 
##                         1                         1                         2 
##                  Cottonee                Whimsicott                   Petilil 
##                         1                         2                         1 
##                 Lilligant                  Basculin                   Sandile 
##                         2                         2                         1 
##                  Krokorok                Krookodile                  Darumaka 
##                         1                         2                         1 
##   DarmanitanStandard Mode        DarmanitanZen Mode                  Maractus 
##                         2                         2                         2 
##                   Dwebble                   Crustle                   Scraggy 
##                         1                         2                         1 
##                   Scrafty                  Sigilyph                    Yamask 
##                         2                         2                         1 
##                Cofagrigus                  Tirtouga                Carracosta 
##                         2                         1                         2 
##                    Archen                  Archeops                  Trubbish 
##                         1                         2                         1 
##                  Garbodor                     Zorua                   Zoroark 
##                         2                         1                         2 
##                  Minccino                  Cinccino                   Gothita 
##                         1                         2                         1 
##                 Gothorita                Gothitelle                   Solosis 
##                         1                         2                         1 
##                   Duosion                 Reuniclus                  Ducklett 
##                         1                         2                         1 
##                    Swanna                 Vanillite                 Vanillish 
##                         2                         1                         1 
##                 Vanilluxe                  Deerling                  Sawsbuck 
##                         2                         1                         2 
##                    Emolga                Karrablast                Escavalier 
##                         1                         1                         2 
##                   Foongus                 Amoonguss                  Frillish 
##                         1                         2                         1 
##                 Jellicent                 Alomomola                    Joltik 
##                         2                         2                         1 
##                Galvantula                 Ferroseed                Ferrothorn 
##                         2                         1                         2 
##                     Klink                     Klang                 Klinklang 
##                         1                         2                         2 
##                    Tynamo                 Eelektrik                Eelektross 
##                         1                         1                         2 
##                    Elgyem                  Beheeyem                   Litwick 
##                         1                         2                         1 
##                   Lampent                Chandelure                      Axew 
##                         1                         2                         1 
##                   Fraxure                   Haxorus                   Cubchoo 
##                         1                         2                         1 
##                   Beartic                 Cryogonal                   Shelmet 
##                         2                         2                         1 
##                  Accelgor                  Stunfisk                   Mienfoo 
##                         2                         2                         1 
##                  Mienshao                 Druddigon                    Golett 
##                         2                         2                         1 
##                    Golurk                  Pawniard                   Bisharp 
##                         2                         1                         2 
##                Bouffalant                   Rufflet                  Braviary 
##                         2                         1                         2 
##                   Vullaby                 Mandibuzz                   Heatmor 
##                         1                         2                         2 
##                    Durant                     Deino                  Zweilous 
##                         2                         1                         1 
##                 Hydreigon                  Larvesta                 Volcarona 
##                         2                         1                         2 
##                  Cobalion                 Terrakion                  Virizion 
##                         2                         2                         2 
##   TornadusIncarnate Forme     TornadusTherian Forme  ThundurusIncarnate Forme 
##                         2                         2                         2 
##    ThundurusTherian Forme                  Reshiram                    Zekrom 
##                         2                         2                         2 
##   LandorusIncarnate Forme     LandorusTherian Forme                    Kyurem 
##                         2                         2                         2 
##        KyuremBlack Kyurem        KyuremWhite Kyurem      KeldeoOrdinary Forme 
##                         2                         2                         2 
##      KeldeoResolute Forme        MeloettaAria Forme   MeloettaPirouette Forme 
##                         2                         2                         2 
##                  Genesect                   Chespin                 Quilladin 
##                         2                         1                         1 
##                Chesnaught                  Fennekin                   Braixen 
##                         2                         1                         1 
##                   Delphox                   Froakie                 Frogadier 
##                         2                         1                         1 
##                  Greninja                  Bunnelby                 Diggersby 
##                         2                         1                         1 
##                Fletchling               Fletchinder                Talonflame 
##                         1                         1                         2 
##                Scatterbug                    Spewpa                  Vivillon 
##                         1                         1                         1 
##                    Litleo                    Pyroar                   Flabébé 
##                         1                         2                         1 
##                   Floette                   Florges                    Skiddo 
##                         1                         2                         1 
##                    Gogoat                   Pancham                   Pangoro 
##                         2                         1                         2 
##                   Furfrou                    Espurr              MeowsticMale 
##                         2                         1                         2 
##            MeowsticFemale                   Honedge                  Doublade 
##                         2                         1                         2 
##      AegislashBlade Forme     AegislashShield Forme                  Spritzee 
##                         2                         2                         1 
##                Aromatisse                   Swirlix                  Slurpuff 
##                         2                         1                         2 
##                     Inkay                   Malamar                   Binacle 
##                         1                         2                         1 
##                Barbaracle                    Skrelp                  Dragalge 
##                         2                         1                         2 
##                 Clauncher                 Clawitzer                Helioptile 
##                         1                         2                         1 
##                 Heliolisk                    Tyrunt                 Tyrantrum 
##                         2                         1                         2 
##                    Amaura                   Aurorus                   Sylveon 
##                         1                         2                         2 
##                  Hawlucha                   Dedenne                   Carbink 
##                         2                         1                         2 
##                     Goomy                   Sliggoo                    Goodra 
##                         1                         2                         2 
##                    Klefki                  Phantump                 Trevenant 
##                         2                         1                         2 
##     PumpkabooAverage Size       PumpkabooSmall Size       PumpkabooLarge Size 
##                         1                         1                         1 
##       PumpkabooSuper Size     GourgeistAverage Size       GourgeistSmall Size 
##                         1                         2                         2 
##       GourgeistLarge Size       GourgeistSuper Size                  Bergmite 
##                         2                         2                         1 
##                   Avalugg                    Noibat                   Noivern 
##                         2                         1                         2 
##                   Xerneas                   Yveltal          Zygarde50% Forme 
##                         2                         2                         2 
##                   Diancie       DiancieMega Diancie       HoopaHoopa Confined 
##                         2                         2                         2 
##        HoopaHoopa Unbound                 Volcanion 
##                         2                         2 
## 
## Within cluster sum of squares by cluster:
## [1]  911966.2 2007145.9
##  (between_SS / total_SS =  31.9 %)
## 
## Available components:
## 
## [1] "cluster"      "centers"      "totss"        "withinss"     "tot.withinss"
## [6] "betweenss"    "size"         "iter"         "ifault"

Based on the result above, the ratio between the BSS/TSS is 31.9 %. The ideal scores for this particular ratio is near 100%. Means our BSS/TSS score is still less than ideal. However, since the process of choosing k is basically objective, we are still going to use these 2 clusters for our analysis.

3.4 Cluster Analysis & Profiling

Now we’ll try to visualize our clustering results for easier read.

library(RColorBrewer)
poke_cluster <- as.matrix(poke_df)

cluster <- c(1: 2)
center_df <- data.frame(cluster, poke_km$centers)

hm.palette <-colorRampPalette(rev(brewer.pal(10, 'Spectral')),space='Lab')

# Reshape the data
center_reshape <- gather(center_df, features, values, HP : SPD)
#head(center_reshape)

#plot data
semplot <- ggplot(data = center_reshape, 
                 aes(x = features, y = cluster)) +
  scale_y_continuous(breaks = seq(1, 2, by = 1)) +
  geom_tile(aes(fill = values)) +
  geom_text(aes(label = round(values,2)), 
            size = 8, 
            color = "white")+
  coord_equal() +
  scale_fill_gradientn(colours = "Black") +
  scale_fill_gradientn(colours = hm.palette(90)) +
  labs(
    title = "Clustering using K = 2"
  ) +
  theme_minimal() +
  theme(plot.background = element_rect(fill = "Black", 
                                       color = "Black"),
        plot.title = element_text(color = "#FFF3DC", 
                                  family = "Bangers",
                                  size = 20),
        panel.background = element_rect(fill = "Black"),
        panel.grid = element_line(colour = "Black"),
        panel.grid.major.x = element_line(colour = "Black"),
        panel.grid.minor.x = element_line(colour = "Black"),
        legend.position = "none",
        axis.text.x = element_text(color = "#FFF3DC", 
                                   family = "Bangers",
                                   size = 17,
                                   angle = 45, 
                                   vjust = 1, 
                                   hjust = 1),
        axis.text.y = element_text(color = "#FFF3DC", 
                                   family = "Bangers",
                                   size = 17),
        axis.ticks = element_blank())

# Save to our assets
ggsave("Assets/semplot.png", semplot, height=2, width=5)

# Call it again using knitr
knitr::include_graphics("Assets/semplot.png")

Insights that we can take from the plot above are:

  • Pokémons in Cluster 2 are generally stronger in all aspects of their Basic Stats.

  • Pokémons in Cluster 1 are generally weaker in all aspects of their Basic Stats.

Based on the profiles above, we will labels our two clusters as:

  • Strong Pokemon for Pokémons in Cluster 2.

  • Weak Pokemon for Pokémons in Cluster 1.

And we will see the distributions between those two Clusters:

pokemon <- pokemon %>% 
  mutate(Cluster = poke_km$cluster)

poke_s <- pokemon %>% 
  filter(Cluster %in% 2)

poke_w <- pokemon %>% 
  filter(Cluster %in% 1)

poke_clustdist <- data.frame(Weak = nrow(poke_w),
                             Strong = nrow(poke_s)) %>% 
  pivot_longer(cols=c('Weak', 'Strong'),
                    names_to='Cluster',
                    values_to='Total')

poke_clustdist %>% 
  e_charts(x = Cluster) %>% 
  e_pie(Total,
        roseType = "radius",
        radius = c("25%", "70%"), 
        legend= FALSE, 
        label = list(
          color = "White",
          fontFamily = "Rockwell",
          fontSize = 14
        ),
        animationDuration = 4000) %>%
  e_title(text = "CLUSTER PROPORTIONS",
          textStyle = list(
            color = "#1DC9C8",
            fontFamily = "Rockwell",
            fontSize = 22
          ),
          right = "10%",
          left = "33%") %>% 
  e_color(c("#1DC9C8","#C8443F"),
          "Black") %>% 
  e_tooltip(formatter = htmlwidgets::JS("
                                        function(params)
                                        {
                                            return `<strong style='color:Black;'>Count:</strong> ${params.value}
                                                    <br/><strong style='color:Black;'>Percent:</strong> ${params.percent}%`
                                        }  "))

Based on the plot above we can see that our clusters separation are almost perfectly proportional with 53.25% considered as Strong Pokemon & 46.75% considered as Weak Pokemon.

4. Conclusions

We can pull some conclusions regarding our dataset based on the clustering process:

 

A work by Rangga Gemilang

gemilang.rangga94@gmail.com

R Language