This blog post is dedicated to the analysis using data visualization of the Pokemon dataset. The first part will be the exploratory analysis. The second part will have a machine learning aspect to it. Both blog-posts will be in R.
Import the libraries.
library(dplyr)
##
## Attaching package: 'dplyr'
## The following objects are masked from 'package:stats':
##
## filter, lag
## The following objects are masked from 'package:base':
##
## intersect, setdiff, setequal, union
library(ggplot2)
library(gridExtra)
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
library(tidyr)
library(reshape2)
##
## Attaching package: 'reshape2'
## The following object is masked from 'package:tidyr':
##
## smiths
library(RColorBrewer)
library(ggrepel)
df = read.csv(file="pokemon.csv")
df = tbl_df(df)
colnames(df)[25] <- "classification"
df$capture_rate <- as.numeric(df$capture_rate)
head(df)
# df[rowSums(is.na(df))>0,]
# df[is.na(df$type2)] <- "None"
# # df[is.na(df$weight_kg)] <- 0
# gsub(df$weight_kg, NA, 0)
#
# df[rowSums(is.na(df))>0,]
df_fight_against <- select(df, type1, against_bug:against_water)
df = select(df, name, classification, hp, weight_kg, height_m, speed, attack, defense, sp_attack, sp_defense, type1, type2, abilities, generation, is_legendary, capture_rate)
head(df)
table(df$capture_rate)
##
## 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
## 6 55 3 5 2 6 1 2 7 1 1 2 11 75 19 1 2 15 7 13
## 21 22 23 24 25 26 27 28 29 30 31 32 33 34
## 69 58 20 1 1 250 7 3 50 3 4 61 2 38
head(df_fight_against)
Density Plot of HP.
density_hp <- ggplot(data=df, aes(hp)) + geom_density(col="white",fill="pink", alpha=0.8) + ggtitle("Density Plot of HP")
density_speed <- ggplot(data=df, aes(speed)) + geom_density(col="white", fill="darkorchid", alpha=0.8) + ggtitle("Density Plot of Speed Characterstics")
density_attack <- ggplot(data=df, aes(attack)) + geom_density(col="white", fill="orange", alpha=0.7) + ggtitle("Density Plot of Attack Characterstics")
density_defense <- ggplot(data=df, aes(defense)) + geom_density(col="white", fill="firebrick", alpha=0.7) + ggtitle("Density Plot of Defense Characterstics")
density_height <- ggplot(data=df, aes(height_m)) + geom_density(col="white", fill="slateblue1", alpha=0.8) + ggtitle("Density Plot of Height (m) ")
density_weight <- ggplot(data=df, aes(weight_kg)) + geom_density(col="white", fill="mediumturquoise", alpha=0.8) + ggtitle("Density Plot of Weight (kg)")
grid.arrange(density_hp, density_speed, density_attack, density_defense, density_height, density_weight, ncol=2)
## Warning: Removed 20 rows containing non-finite values (stat_density).
## Warning: Removed 20 rows containing non-finite values (stat_density).
Distribution of Types of Pokemon based on Primary and Secondary type.
# ill=c("gray", "black", "pink", "yellow", "pink", "orange", "red", "blue", "purple", "green", "brown", "blue", "gray", "violet", "blue", "black", "gray", "blue")
type_1_poke <- ggplot(data=df, aes(type1)) + geom_bar(aes(fill=..count..), alpha=0.8) + theme(axis.text.x = element_text(angle = 90, hjust = 0)) + ggtitle("Distribution Based on Type-1") + coord_flip()
type_2_poke <- ggplot(data=df, aes(type2)) + geom_bar(aes(fill=..count..), alpha=0.8) + theme(axis.text.x = element_text(angle = 90, hjust = 0)) + ggtitle("Distribution Based on Type-2") + coord_flip()
grid.arrange(type_1_poke, type_2_poke, ncol=2)
Distribution of Legendary Pokemons based on their Primary Type
df %>%
filter(is_legendary==1) %>%
ggplot(aes(type1)) + geom_bar(aes(fill= ..count..)) + theme(axis.text.x = element_text(angle=90, hjust=0)) + ggtitle("Number of Legendary Pokemons Based on Type-1")
Diiferent Pokemons Types Introduced in Each Generation(1-7)
# ggplot(df, aes(speed, capture_rate)) + geom_()
bug = filter(df, type1 == "bug")
dark = filter(df, type1 == "dark")
dragon = filter(df, type1 == "dragon")
electric = filter(df, type1 == "electric")
fairy = filter(df, type1 == "fairy")
fire = filter(df, type1 == "fire")
flying = filter(df, type1 == "flying")
ghost = filter(df, type1 == "ghost")
grass = filter(df, type1 == "grass")
ground = filter(df, type1 == "ground")
ice = filter(df, type1 == "ice")
normal = filter(df, type1 == "normal")
psychic = filter(df, type1 == "psychic")
rock = filter(df, type1 == "rock")
steel= filter(df, type1 == "steel")
water = filter(df, type1 == "water")
gen_bug <- ggplot(bug, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Bug") + scale_fill_gradient(low="black", high="brown")
gen_dark <- ggplot(dark, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Dark") + scale_fill_gradient(low="black", high="purple")
gen_dragon <- ggplot(dragon, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Dragon") + scale_fill_gradient(low="black", high="orange")
gen_electric <- ggplot(electric, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Electric") + scale_fill_gradient(low="black", high="yellow")
gen_fairy <- ggplot(fairy, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Fairy") + scale_fill_gradient(low="black", high="pink")
gen_fire <- ggplot(fire, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Fire") + scale_fill_gradient(low="black", high="red")
gen_flying <- ggplot(flying, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Flying") + scale_fill_gradient(low="black", high="lightblue")
gen_ghost <- ggplot(ghost, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Ghost") + scale_fill_gradient(low="black", high="gray")
gen_grass <- ggplot(grass, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Grass") + scale_fill_gradient(low="black", high="green")
gen_ground <- ggplot(ground, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Ground") + scale_fill_gradient(low="black", high="brown")
gen_ice <- ggplot(ice, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Ice") + scale_fill_gradient(low="black", high="darkblue")
gen_normal <- ggplot(normal, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Normal") + scale_fill_gradient(low="black", high="orange")
gen_psychic <- ggplot(psychic, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Psychic") + scale_fill_gradient(low="black", high="violet")
gen_rock <- ggplot(rock, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Rock") + scale_fill_gradient(low="black", high="brown")
gen_steel <- ggplot(steel, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("Steel") + scale_fill_gradient(low="black", high="lightgray")
gen_water <- ggplot(water, aes(generation)) + geom_histogram(aes(fill = ..count..)) + ggtitle("water") + scale_fill_gradient(low="black", high="blue")
grid.arrange(gen_bug, gen_dark, gen_dragon, gen_electric, gen_fairy, gen_fire, gen_flying, gen_ghost, gen_grass, gen_ground, gen_ice, gen_normal, gen_psychic, gen_rock, gen_steel, gen_water, ncol=4)
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
## `stat_bin()` using `bins = 30`. Pick better value with `binwidth`.
Defence vs Attack Characterstics of Pokemons
ggplot(data=df, aes(attack, defense)) + geom_point(aes(color=is_legendary), alpha=0.8) + scale_color_gradient(low="darkblue", high="red") + ggtitle("Defense vs Attack Characterstics") + geom_label_repel(data=subset(df, attack > 150 | defense >150 | attack < 25), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50')
# geom_text(aes(label=ifelse(attack>150 | attack <30 | defense>150, as.character(name), '')))
speed_attack_legendary <- ggplot(na.omit(df), aes(attack, speed)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, (attack > 170 | attack < 50 & speed >150 | speed < 50) & is_legendary == 1 | speed > 145), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + geom_smooth(method = "lm")
weight_attack_legendary <- ggplot(na.omit(df), aes(attack, weight_kg)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, (attack > 170 | attack < 50 | weight_kg > 650) & (is_legendary == 1)), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + geom_smooth(method = "lm")
height_attack_legendary <- ggplot(na.omit(df), aes(attack, height_m)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, ((attack > 170 | attack < 50 | height_m > 7.5) & is_legendary == 1) | height_m > 5 & is_legendary == 0), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + geom_smooth(method = "lm")
hp_attack_legendary <- ggplot(na.omit(df), aes(attack, hp)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, ((attack > 170 | hp > 190 | attack < 50) & is_legendary == 1) | hp >160), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + geom_smooth(method = "lm")
grid.arrange(speed_attack_legendary, weight_attack_legendary, height_attack_legendary, hp_attack_legendary, ncol = 2)
speed_defense_legendary <- ggplot(na.omit(df), aes(defense, speed)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, (defense > 130 | defense < 50| speed > 140 | speed < 50) & is_legendary == 1), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + geom_smooth(method = "lm")
weight_defense_legendary <- ggplot(na.omit(df), aes(defense, weight_kg)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, (defense > 160 | defense < 50 | weight_kg > 600) & is_legendary == 1), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + geom_smooth(method = "lm")
height_defense_legendary <- ggplot(na.omit(df), aes(defense, height_m)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, (defense > 150 | defense < 50 | height_m > 6) & is_legendary == 1 | height_m >5 & is_legendary ==0), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + geom_smooth(method = "lm")
hp_defense_legendary <- ggplot(na.omit(df), aes(defense, hp)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, (defense > 150 | defense < 50 | hp > 150) & is_legendary == 1 | hp > 200), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50') + geom_smooth(method = "lm")
grid.arrange(speed_defense_legendary, weight_defense_legendary, height_defense_legendary, hp_defense_legendary, ncol = 2)
# ggplot(na.omit(df), aes(attack, weight_kg)) + geom_point(aes(color=is_legendary)) + geom_label_repel(data=subset(df, attack < 50 & defense < 50 & is_legendary == 1 ), aes(label=name), box.padding = 0.35, point.padding = 0.5, segment.color = 'grey50')
Speed vs Weight of pokemon according to primary type
# weight_speed_bug <- ggplot(bug, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Bug") + scale_color_gradient(low="black", high="brown")
# weight_speed_dark <- ggplot(dark, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Dark") + scale_color_gradient(low="black", high="purple")
# weight_speed_dragon <- ggplot(dragon, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary))+ ggtitle("Dragon") + scale_color_gradient(low="black", high="orange")
# weight_speed_electric <- ggplot(electric, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Electric") + scale_color_gradient(low="black", high="yellow")
# weight_speed_fairy <- ggplot(fairy, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Fairy") + scale_color_gradient(low="black", high="pink")
# weight_speed_fire <- ggplot(fire, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary))+ ggtitle("Fire") + scale_color_gradient(low="black", high="red")
# weight_speed_flying <- ggplot(flying, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Flying") + scale_color_gradient(low="black", high="lightblue")
# weight_speed_ghost <- ggplot(ghost, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Ghost") + scale_color_gradient(low="black", high="gray")
# weight_speed_grass <- ggplot(grass, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary))+ ggtitle("Grass") + scale_color_gradient(low="black", high="green")
# weight_speed_ground <- ggplot(ground, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Ground") + scale_color_gradient(low="black", high="brown")
# weight_speed_ice <- ggplot(ice, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Ice") + scale_color_gradient(low="black", high="darkblue")
# weight_speed_normal <- ggplot(normal, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Normal") + scale_color_gradient(low="black", high="orange")
# weight_speed_psychic <- ggplot(psychic, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary))+ ggtitle("Psychic") + scale_color_gradient(low="black", high="violet")
# weight_speed_rock <- ggplot(rock, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary))+ ggtitle("Rock") + scale_color_gradient(low="black", high="brown")
# weight_speed_steel <- ggplot(steel, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("Steel") + scale_color_gradient(low="black", high="lightgray")
# weight_speed_water <- ggplot(water, aes(weight_kg, speed)) + geom_point(aes(color=is_legendary)) + ggtitle("water") + scale_color_gradient(low="black", high="blue")
#
#
# grid.arrange(weight_speed_bug, weight_speed_dark, weight_speed_dragon, weight_speed_electric, weight_speed_fairy, weight_speed_fire, weight_speed_flying, weight_speed_ghost, weight_speed_grass, weight_speed_ground, weight_speed_ice, weight_speed_normal, weight_speed_psychic, weight_speed_rock, weight_speed_steel, weight_speed_water, ncol=4)
Pokemons with higher attack ratings are faster.
ggplot(df, aes(attack, defense)) + geom_jitter(aes(col=speed)) + scale_color_gradient(low="blue", high="darkorange") + ggtitle("Defense vs Attack wrt Speed")
Boxplot of pokemon characterstics.
box_plot_attr <- select(df, type1, is_legendary, hp, defense, attack, sp_attack, sp_defense, speed)
box_plot_attr_leg <- filter(box_plot_attr, is_legendary == 1)
box_plot_attr_nor <- filter(box_plot_attr, is_legendary == 0)
box_plot_attr_leg_long <- gather(box_plot_attr_leg, attribute, value, -c(type1, is_legendary))
box_plot_attr_nor_long <- gather(box_plot_attr_nor, attribute, value, -c(type1, is_legendary))
bp_leg <- ggplot(data = box_plot_attr_leg_long, aes(attribute, value)) + geom_boxplot(fill="green4") + ggtitle("Legendary Pokemons")
bp_nor <- ggplot(data = box_plot_attr_nor_long, aes(attribute, value)) + geom_boxplot(fill = "yellow2") + ggtitle("Normal Pokemons")
grid.arrange(bp_leg, bp_nor,ncol=2)
Violin plot of Pokemon Characterstics.
vp_leg <- ggplot(data = box_plot_attr_leg_long, aes(attribute, value)) + geom_violin(fill="green4") + ggtitle("Legendary Pokemons")
vp_nor <- ggplot(data = box_plot_attr_nor_long, aes(attribute, value)) + geom_violin(fill="yellow2") + ggtitle("Normal Pokemons")
grid.arrange(vp_leg, vp_nor,ncol=2)
Heatmap with mean of attributes for different types of Pokemons differentiated on Legendary and Non-Legendary.
hmap_attr <- select(df, type1, is_legendary, hp, defense, attack, sp_attack, sp_defense, speed, height_m, weight_kg)
hmap_attr_leg <- filter(hmap_attr, is_legendary == 1)
hmap_attr_nor <- filter(hmap_attr, is_legendary == 0)
hmap_attr_leg <- group_by(hmap_attr_leg, type1)
hmap_attr_nor <- group_by(hmap_attr_nor, type1)
hmap_attr_leg <- summarise(hmap_attr_leg, hp=mean(hp), attack=mean(attack), defense=mean(defense), sp_attack=mean(sp_attack), sp_defense=mean(sp_defense), speed=mean(speed))
hmap_attr_leg_m <- melt(hmap_attr_leg)
## Using type1 as id variables
hmap_attr_nor <- summarise(hmap_attr_nor, hp=mean(hp), attack=mean(attack), defense=mean(defense), sp_attack=mean(sp_attack), sp_defense=mean(sp_defense), speed=mean(speed))
hmap_attr_nor_m <- melt(hmap_attr_nor)
## Using type1 as id variables
hm.palette <- colorRampPalette(rev(brewer.pal(5, 'RdYlBu')), space='Lab')
ggplot(data=hmap_attr_leg_m, aes(type1, variable)) + geom_tile(aes(fill=value)) + ggtitle("Legendary Pokemon: Type1 - Attribute") + scale_fill_gradientn(colours = hm.palette(100)) + theme(axis.text.x = element_text(angle=90, hjust=0)) + coord_equal()
hm.palette <- colorRampPalette(rev(brewer.pal(5, 'RdYlBu')), space='Lab')
ggplot(data=hmap_attr_nor_m, aes(type1, variable)) + geom_tile(aes(fill=value)) + ggtitle("Non-Legendary Pokemon: Type1 - Attribute") + scale_fill_gradientn(colours = hm.palette(100)) + theme(axis.text.x = element_text(angle=90, hjust=0)) + coord_equal()
Correlation between the the different attributes of Legendary and Non Legendary Pokemons.
hmap_attr <- select(df, type1, is_legendary, hp, defense, attack, sp_attack, sp_defense, speed)
hmap_attr_leg <- filter(hmap_attr, is_legendary == 1)
hmap_attr_nor <- filter(hmap_attr, is_legendary == 0)
hmap_attr_leg <- group_by(hmap_attr_leg, type1)
hmap_attr_nor <- group_by(hmap_attr_nor, type1)
hmap_attr_leg <- summarise(hmap_attr_leg, hp=mean(hp), attack=mean(attack), defense=mean(defense), sp_attack=mean(sp_attack), sp_defense=mean(sp_defense), speed=mean(speed))
hmap_attr_nor <- summarise(hmap_attr_nor, hp=mean(hp), attack=mean(attack), defense=mean(defense), sp_attack=mean(sp_attack), sp_defense=mean(sp_defense), speed=mean(speed))
row.names(hmap_attr_leg) <- hmap_attr_leg$type1
## Warning: Setting row names on a tibble is deprecated.
hmap_attr_leg$type1 <- NULL
hmap_attr_leg$is_legendary <- NULL
row.names(hmap_attr_nor) <- hmap_attr_nor$type1
## Warning: Setting row names on a tibble is deprecated.
hmap_attr_nor$type1 <- NULL
hmap_attr_nor$is_legendary <- NULL
hmap_attr_leg_cor <- cor(hmap_attr_leg)
hmap_attr_leg_cor_m <- melt(hmap_attr_leg_cor)
hm.palette <- colorRampPalette(rev(brewer.pal(5, 'GnBu')), space='Lab')
ggplot(data=hmap_attr_leg_cor_m, aes(Var1, Var2)) + geom_tile(aes(fill=value)) + ggtitle("Attribute Correlation - Legendary") + scale_fill_gradientn(colours = hm.palette(100)) + coord_equal()
hmap_attr_nor_cor <- cor(hmap_attr_nor)
hmap_attr_nor_cor_m <- melt(hmap_attr_nor_cor)
hm.palette <- colorRampPalette(rev(brewer.pal(5, 'GnBu')), space='Lab')
ggplot(data=hmap_attr_nor_cor_m, aes(Var1, Var2)) + geom_tile(aes(fill=value)) + ggtitle("Attribute Correlation - Normal") + scale_fill_gradientn(colours = hm.palette(100)) + coord_equal()
# kclust_attr <- select(df, name, hp, attack, defense, height_m, weight_kg, speed)
# kclust_attr <- na.omit(kclust_attr)
# att_def <- kclust_attr[3:4]
# km_att_def<- kmeans(att_def, 2, nstart=100)
#
# ggplot(data=kclust_attr, aes(attack, defense, label=name)) + geom_point(aes(color=km_att_def$cluster)) + geom_text(aes(label=ifelse(attack>130 | attack <30 | defense>150, as.character(name), ''))) + ggtitle("Pokemons good for battles")
#
# # plot(kclust_attr$attack, kclust_attr$defense, labels=att_def$name)
# # text(x=kclust_attr$attack, y=kclust_attr$defense, labels = kclust_attr$name)
# K-MEANS ELBOW METHOD
# mydata <- my_dataset
# wss <- (nrow(mydata)-1)*sum(apply(mydata,2,var))
# for (i in 2:15) wss[i] <- sum(kmeans(mydata,
# centers=i)$withinss)
# plot(1:15, wss, type="b", xlab="Number of Clusters",
# ylab="Within groups sum of squares")
df_fight_against_g <- group_by(df_fight_against, type1)
df_fight_against_summ <- summarise(df_fight_against_g, against_bug = mean(against_bug), against_dark = mean(against_dark), against_dragon = mean(against_dragon), against_electric = mean(against_electric), against_fairy = mean(against_fairy), against_fight = mean(against_fight), against_fire = mean(against_fire), against_flying = mean(against_flying), against_ghost = mean(against_ghost), against_grass = mean(against_grass), against_ground = mean(against_ground), against_ice = mean(against_ice), against_normal = mean(against_normal), against_poison = mean(against_poison), against_psychic = mean(against_psychic), against_rock = mean(against_rock), against_steel = mean(against_steel), against_water = mean(against_water))
# df_fight_against_summ
df_fight_against_long <- melt(df_fight_against_summ)
## Using type1 as id variables
# df_fight_against_long
hm.palette <- colorRampPalette(rev(brewer.pal(9, 'RdYlBu')), space='Lab')
ggplot(data=df_fight_against_long, aes(type1, variable)) + geom_tile(aes(fill=value)) + scale_fill_gradientn(colours = hm.palette(100)) + coord_equal() + theme(axis.text.x=element_text(angle=90, hjust=0)) + ggtitle("Effectiveness of different types of Pokemons")
Thank you for reading. Suggestions and constructive criticism are welcome. :) You can find me on LinkedIn. You can view my other blog posts here.