以R绘制:每个类别的特定颜色

时间:2019-05-20 18:28:28

标签: r plotly heatmap

我正在尝试使用包含以下数据的数据构建热图:

dataset <- data.frame(ID = c(rep('population', 8), rep('sub_population', 8)),
       TYPE = rep(c('one', 'two', 'three', 'for', 'five', 'six', 'seven', 'eight'),2),
       COUNT = rep(c(1,2,3,4,5,6,7,8),2)
       ) %>%
mutate(TEXT = paste(TYPE, 'has:', COUNT))

我的目标是生成一个Plotly热图,其中 ID 是热图中的两个独立行,每个类别/ TYPE 均带有正方形。

在每个正方形中,我都希望 COUNT 作为文本,当我将鼠标悬停在正方形上时,我想显示“ TEXT”列。

困难的部分是我希望每种类别都有特定的颜色(即 TYPE )。例如,类型onethreegrayfoursevenred,而eight为{{1 }}。

我现在有:

blue

我已经尝试过Specifying the colors in a Plotly Heatmap中给出的提示,但尚未弄清楚。

0 个答案:

没有答案