如何调整 heatmap.2 中的颜色范围
How to adjust the color range in heatmap.2
我正在尝试使用 R 语言绘制热图。
绘制热图后,发现我的热图不适合解释,因为颜色键的范围没有调整好。
正如您在下面看到的,与我的数据分布相比,色键范围非常长。(它们介于 0 到 4 之间)。因此,热图中的所有颜色都是绿色。
如何解决这个问题?
下面是我的代码。
(我试图搜索解决方案,但未能找到适合我的案例的线程。)
library(gplots)
matrix <- as.matrix(read.delim("bladder",header=FALSE))
hclustfunc <- function(x) hclust(x, method="complete")
distfunc <- function(x) dist(x, method="euclidean")
cl.col <- hclustfunc(distfunc(t(matrix)))
gr.col <- cutree(cl.col, 4)
heatmap.2(as.matrix(matrix),col=greenred(75),dendrogram=c("col"),trace="none",Rowv=FALSE,margins = c(8,16),cexRow=0.60,cexCol=0.8)
确保在以下示例中将 n
设置为正确的长度:
my_palette <- colorRampPalette(c("red", "blue", "green"))(n = 100)
heatmap.2(as.matrix(matrix), col=my_palette,
breaks=colors, density.info="none", trace="none",
dendrogram=c("row"), symm=F,symkey=F,symbreaks=T, scale="none")
我正在尝试使用 R 语言绘制热图。
绘制热图后,发现我的热图不适合解释,因为颜色键的范围没有调整好。
正如您在下面看到的,与我的数据分布相比,色键范围非常长。(它们介于 0 到 4 之间)。因此,热图中的所有颜色都是绿色。
如何解决这个问题?
下面是我的代码。 (我试图搜索解决方案,但未能找到适合我的案例的线程。)
library(gplots)
matrix <- as.matrix(read.delim("bladder",header=FALSE))
hclustfunc <- function(x) hclust(x, method="complete")
distfunc <- function(x) dist(x, method="euclidean")
cl.col <- hclustfunc(distfunc(t(matrix)))
gr.col <- cutree(cl.col, 4)
heatmap.2(as.matrix(matrix),col=greenred(75),dendrogram=c("col"),trace="none",Rowv=FALSE,margins = c(8,16),cexRow=0.60,cexCol=0.8)
确保在以下示例中将 n
设置为正确的长度:
my_palette <- colorRampPalette(c("red", "blue", "green"))(n = 100)
heatmap.2(as.matrix(matrix), col=my_palette,
breaks=colors, density.info="none", trace="none",
dendrogram=c("row"), symm=F,symkey=F,symbreaks=T, scale="none")