保持不同热图的 pheatmap 颜色范围相同
Keeping the pheatmap color range the same for different heat maps
我有以下代码来制作两个不同的代表相关矩阵的 pheatmaps。
A1 <- c(1,2,3,4)
B1 <- c(2,4,3,1)
C1 <- c(2,4,3,5)
D1 <- c(2,3,1,4)
E1 <- c(2,1,4,5)
Gene <- c(1,2,3,4)
df1 <- data.frame(Gene, A1, B1, C1, D1, E1)
CorMatrix1 <- cor(df1[, c("A1","B1","C1","D1","E1")])
CorMatrix1
pheatmap(CorMatrix1)
A2 <- c(2,5,6,4)
B2 <- c(4,8,9,3)
C2 <- c(5,7,8,1)
D2 <- c(1,2,6,4)
E2 <- c(3,7,5,4)
Gene <- c(1,2,3,4)
df2 <- data.frame(Gene, A2, B2, C2, D2, E2)
CorMatrix2 <- cor(df2[, c("A2","B2","C2","D2","E2")])
CorMatrix2
pheatmap(CorMatrix2)
我的问题很简单,我怎样才能操纵作弊图的色标,使两个作弊图的色标相同?例如,如何使两个作弊图上的色标从 -0.5 变为 1?
考虑设置您自己的图例范围,包括颜色应该改变的时间间隔。
# load package for color range
library(RColorBrewer)
# define range (e.g., -0.5 to 1) and step size (e.g., 0.2)
breaksList = seq(-0.5, 1, by = 0.2)
# plot matrix1 with new range
pheatmap(CorMatrix1,
color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(length(breaksList)),
breaks = breaksList)
# plot matrix2 with new range
pheatmap(CorMatrix2,
color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(length(breaksList)),
breaks = breaksList)
我有以下代码来制作两个不同的代表相关矩阵的 pheatmaps。
A1 <- c(1,2,3,4)
B1 <- c(2,4,3,1)
C1 <- c(2,4,3,5)
D1 <- c(2,3,1,4)
E1 <- c(2,1,4,5)
Gene <- c(1,2,3,4)
df1 <- data.frame(Gene, A1, B1, C1, D1, E1)
CorMatrix1 <- cor(df1[, c("A1","B1","C1","D1","E1")])
CorMatrix1
pheatmap(CorMatrix1)
A2 <- c(2,5,6,4)
B2 <- c(4,8,9,3)
C2 <- c(5,7,8,1)
D2 <- c(1,2,6,4)
E2 <- c(3,7,5,4)
Gene <- c(1,2,3,4)
df2 <- data.frame(Gene, A2, B2, C2, D2, E2)
CorMatrix2 <- cor(df2[, c("A2","B2","C2","D2","E2")])
CorMatrix2
pheatmap(CorMatrix2)
我的问题很简单,我怎样才能操纵作弊图的色标,使两个作弊图的色标相同?例如,如何使两个作弊图上的色标从 -0.5 变为 1?
考虑设置您自己的图例范围,包括颜色应该改变的时间间隔。
# load package for color range
library(RColorBrewer)
# define range (e.g., -0.5 to 1) and step size (e.g., 0.2)
breaksList = seq(-0.5, 1, by = 0.2)
# plot matrix1 with new range
pheatmap(CorMatrix1,
color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(length(breaksList)),
breaks = breaksList)
# plot matrix2 with new range
pheatmap(CorMatrix2,
color = colorRampPalette(rev(brewer.pal(n = 7, name = "RdYlBu")))(length(breaksList)),
breaks = breaksList)