geom_tile热图,具有基于因子的不同高填充颜色

Mic*_*ael 12 r heatmap ggplot2

我感兴趣的建设有一个热图geom_tileGGPLOT2使用基于一个因素不同梯度高显色性.

下图创建了一个图,其中各个图块的颜色为蓝色或红色xy_type,但没有渐变.

ggplot() + 
  geom_tile(data=mydata, aes(x=factor(myx), y=myy, fill=factor(xy_type))) + 
  scale_fill_manual(values=c("blue", "red"))
Run Code Online (Sandbox Code Playgroud)

下面的图表不使用xy_type因子来选择颜色,但我得到一个基于的单个渐变xy_avg_value.

ggplot() + 
  geom_tile(data=mydata, aes(x=factor(myx), y=myy, fill=xy_avg_value))
Run Code Online (Sandbox Code Playgroud)

有没有一种技术可以混合这两个图?我可以使用a facet_grid(xy_type ~ .)来创建具有渐变的这些数据的单独图.由于这最终将成为一个地图(x~y坐标),我想找到一种方法在一个geom_tile地图中一起显示不同的渐变.

jor*_*ran 20

一般来说,ggplot2不允许单一类型的多个比例(即多个颜色或填充比例),所以我怀疑这不是(容易)可能的.

我能想出的最接近的最近似是:

df <- data.frame(expand.grid(1:5,1:5))
df$z <- runif(nrow(df))
df$grp <- rep(letters[1:2],length.out = nrow(df))

ggplot(df,aes(x = Var1,y = Var2,fill = factor(grp),alpha = z)) + 
    geom_tile() + 
    scale_fill_manual(values = c('red','blue'))
Run Code Online (Sandbox Code Playgroud)

在此输入图像描述

但要获得一个明智的传奇将是艰难的.