口袋妖怪游戏结果可视化与调色板的选择

口袋妖怪游戏结果可视化与调色板的选择

这篇博客是学习:zonination/pokemon-chart的笔记,是一个热力图的绘制。另外介绍了scale_fill(color)_brewer()中色板的选择。

首先准备绘图数据:
口袋妖怪.csv

整理数据

R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
library(ggplot2)
library(reshape2)
poke <- read.csv("口袋妖怪.csv",
stringsAsFactors = F)

View(poke)
# 宽变长
poke <- melt(poke, id.vars = c("Attacking"))
names(poke) <- c("Attacking", "Defending", "Damage")

poke$Damage <- as.character(poke$Damage)
poke$Attacking <- factor(poke$Attacking)
poke$Defending <- factor(poke$Defending,
levels = levels(poke$Defending)[order(levels(poke$Defending))])
poke$Attacking <- factor(poke$Attacking,
levels = levels(poke$Attacking)[order(levels(poke$Attacking),
decreasing = T)])

绘图

scale_fill(color)_brewer()中色板的选择可以在这个网站上找到:colorbrewer2

R
1
2
3
4
5
6
7
8
9
10
11
ggplot(poke, aes(Defending, Attacking)) +
geom_tile(aes(fill = Damage), color = 'white') +
scale_fill_brewer(palette = "BuGn",
labels = c("无伤害(0%)",
"无有效伤害(50%)",
"正常伤害(100%)",
"超级伤害(200%)")) +
ylab("攻击类型") +
xlab("防守类型") +
theme_bw(base_size = 20, base_family = 'STSong') +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

R
1
2
3
4
5
6
7
8
9
10
11
ggplot(poke, aes(Defending, Attacking)) +
geom_tile(aes(fill = Damage), color = 'white') +
scale_fill_brewer("伤害", palette = "Accent",
labels = c("无伤害(0%)",
"无有效伤害(50%)",
"正常伤害(100%)",
"超级伤害(200%)")) +
ylab("攻击类型") +
xlab("防守类型") +
theme_bw(base_size = 20, base_family = 'STSong') +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

R
1
2
3
4
5
6
7
8
9
10
11
ggplot(poke, aes(Defending, Attacking)) +
geom_tile(aes(fill = Damage), color = 'white') +
scale_fill_brewer("伤害", palette = "Dark2",
labels = c("无伤害(0%)",
"无有效伤害(50%)",
"正常伤害(100%)",
"超级伤害(200%)")) +
ylab("攻击类型") +
xlab("防守类型") +
theme_bw(base_size = 20, base_family = 'STSong') +
theme(axis.text.x = element_text(angle = 90, hjust = 1, vjust = 0.5))

colorbrewer2网站上还有更多的色板选择。

# R

评论

Your browser is out-of-date!

Update your browser to view this website correctly. Update my browser now

×