我正在使用 R 中的 echarts4R 库来创建交互式热图(参见附图)。数据结构如下:
联盟名称 | 属性 | 价值 |
---|---|---|
德甲联赛 | 速度 | 70 |
德甲联赛 | 拍摄 | 60 |
德甲联赛 | 路过 | 64 |
德甲联赛 | 运球 | 70 |
德甲联赛 | 防守 | 62 |
德甲联赛 | 物理 | 71 |
西甲 | 速度 | 70 |
西甲 | 拍摄 | 62 |
西甲 | 路过 | 66 |
西甲 | 运球 | 70 |
这是我使用的代码,其中player_att_plot是具有上述结构的数据框:
player_att_plot %>%
e_charts(league_name) %>%
e_heatmap(attribute,value, itemStyle = list(emphasis = list(shadowBlur = 10))) %>%
e_visual_map(value,inRange = list(color=c("white","green")))
基本上,我希望热图具有特定于每个属性的色标,而不是整个热图。
我尝试将数据框和绘图拆分为单独的系列,然后进行绘图,但没有成功。可能还有另一个包可能更适合该示例,对此的任何指导将不胜感激!
这里通常的方法是使用阿尔法美学:
library(ggplot2)
ggplot(df, aes(league_name, attribute, fill = attribute, alpha = value)) +
geom_tile(color = "gray") +
theme_minimal(base_size = 16) +
coord_cartesian(expand = FALSE) +
theme(panel.grid = element_blank()) +
ggsci::scale_fill_startrek() +
guides(fill = "none")
显然,您可以使用您喜欢的任何填充调色板。
使用的数据
set.seed(1)
df <- data.frame(league_name = rep(c("Bundesliga", "La Liga", "Ligue 1",
"Premier League", "Serie A"), each = 6),
attribute = factor(rep(c("pace", "shooting", "passing",
"dribbling", "defending", "physic"), 5),
c("pace", "shooting", "passing",
"dribbling", "defending", "physic")),
value = sample(59:72, 30, TRUE))