R / ggplot:重复使用多个热图的颜色键 [英] R/ggplot: Reuse color key for multiple heat maps

查看:584
本文介绍了R / ggplot:重复使用多个热图的颜色键的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我生成多个热图以绘制为动画。我想重复使用不同热度图的颜色键以显示随时间的变化。目前,关键是正在重置每个热图。

Heatmap1:( http://i.imgur .com / iPIDY82.png
Heatmap2:( http://i.imgur .com / GvNfQal.png



我希望两个热度图中的总范围相同。所以上面的Heatmap1应该有一个净浅的颜色。



我现在的代码如下:

< pre $ mat < - matrix(unlist(row),ncol = 4,byrow = TRUE)
matm < - melt(mat)
p < - ggplot (data = matm)+
geom_tile(aes(x = X1,y = X2,fill = value),color =white)+
scale_fill_gradient(low =steelblue1,high =steelblue4 )

16个电池。我将它转换为一个矩阵,然后绘制相同。但不同的行有不同的范围,并且范围每次都会重置。



我尝试了以下修改:

[1]向 scale_fill

  scale_fill_gradient(low =steelblue1,high =steelblue4,breaks = seq 3,6.4,by = 0.05))

[2]将数据分解为因子, scale_fill

  row_cut<  -  cut(as.numeric(row ),break = seq(3,6.4,by = 0.05),right = FALSE)
mat < - matrix(unlist(row_cut),ncol = 4,byrow = TRUE)
matm <熔化(mat)
p < - ggplot(data = matm)+
geom_tile(aes(x = X1,y = X2,fill = value),color =white)+
scale_fill_brewer(palette =Blues,intensity,breaks = seq(3,6.4,by = 0.05))

但是这两个修改都没有帮助。



(另外:当我添加中断 scale_fill 图中缺少图例)

解决方案

使用限制参数:

  scale_fill_gradient(...,limits = c(3,6.4))


I am generating multiple heatmaps to be plotted as an animation. I want to reuse the color keys for different heatmaps to show the change with time. Currently the key is being reset for each heatmap.

Heatmap1: (http://i.imgur.com/iPIDY82.png) Heatmap2: (http://i.imgur.com/GvNfQal.png)

I would like the "total range" to be the same in both heatmaps. So Heatmap1 above should have a net "lighter" color.

The code I have at present is as follows:

mat  <- matrix(unlist(row), ncol=4, byrow=TRUE)
matm <- melt (mat)
p    <- ggplot (data=matm) +
        geom_tile (aes(x=X1, y=X2, fill=value), color="white")  +
        scale_fill_gradient (low="steelblue1", high="steelblue4")

row has data for each of the 16 cells. I convert it to a matrix, and then plot the same. But different rows have different ranges, and the range is reset each time.

I have tried the following modifications:

[1] Add breaks to the scale_fill

scale_fill_gradient (low="steelblue1", high="steelblue4",breaks=seq(3,6.4,by=0.05))

[2] Cut the data into factors and add breaks to the scale_fill

row_cut <- cut (as.numeric(row), breaks=seq(3,6.4,by=0.05), right=FALSE)
mat     <- matrix(unlist(row_cut), ncol=4, byrow=TRUE)
matm    <- melt (mat)
p       <- ggplot (data=matm) +
           geom_tile (aes(x=X1, y=X2, fill=value), color="white")  +
           scale_fill_brewer(palette = "Blues","intensity", breaks=seq(3,6.4,by=0.05))

But neither of the modifications helps.

(Aside: When I add breaks to scale_fill the legend is missing in the plots)

解决方案

Use the limits parameter:

scale_fill_gradient(..., limits=c(3, 6.4))

这篇关于R / ggplot:重复使用多个热图的颜色键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆