Entering edit mode
10.4 years ago
f.hastert
•
0
Hi,
I am trying to plot three datasets A, B, C in one heatmap in the order A1, B1, C1, A2, B2, C2.....
using pheatmap
and I'd like to assign a specific colorRampPalette
to each data set, e.g. A = green...grey, B = blue...grey, C = red...grey.
So far I have my datasets arranged as intended, but the coloring is causing troubles as you can see in the last part of the script. I would be happy for any suggestions, as I am bloody R beginner.
So the script I am using is as follows...
#three datasets to be used
library(pheatmap)
A <-c(14,6,4,4,4,6,6,4,5,5,
5,7,5,6,6,11,13,9,7,8,
8,10,10,11,10,9,7,8,8,8,
7,7,10,6,6,4,3,5,4,5,
3,4,3,4,6,5,6,6,7,6,
6,6,7,7,8,8,7,7,7,8,
9,8,9,9,9,10,12,14,10,10,
10,11,11,11,9,11,8,8,6,6,
5,6,6,5,3,3,3,6,4,6,
8,8,8,9,26,301,474,222,120,612,
1016,127,35,22,19,15,13,13,11,11,
12,12,13,12,13,14,15,16,13,11,
8,7,5,5,5,6,4,6,3,5,
5,6,6,8,8,10,13,33,325,526,
262,91,148,176,52,34,28,26,22,22,
24,23,25,25,45,87,93,181,244,110,
71,135,24,12,7,9,16,15,6,4,
2,4,5,5,6,5,6,6,7,9,
11,38,89,71,72,184,250,33,28,25,
26,26,24,31,39,41,42,48,66,86,
70,50,40,83,951,119,14,7,8,9,
8,7,5,4,5,6,6,7,8,7,
9,11,12,13,29,46,34,28,40,52,
22,14,15,20,18,12,15,18,24,26,
28,41,60,47,39,35,44,770,48,13,
10,9,11,9,5,4,4,5,5,6,
8,7,10,9,8,7,15,26,39,30,
25,42,48,20,17,14,23,19,18,22,
24,25,23,29,55,85,66,51,40,53,
729,71,47,40,32,35,16,7,5,6,
6,5,8,8,10,9,9,9,10,11,
21,37,30,26,32,39,22,19,19,20,
21,19,21,22,25,27,28,49,69,70,
78,71,62,450,67,58,40,30,18,8,
6,5,4,4,7,9,8,9,9,11,
11,13,21,102,149,71,46,92,91,33,
25,26,32,27,23,29,33,30,32,41,
93,135,149,232,192,94,295,42,32,28,
33,37,22,7,5,5,6,6,9,7,
7,8,8,8,9,10,12,21,21,18,
31,45,18,14,14,21,22,18,20,23,
23,26,29,36,48,47,40,37,51,592,
182,52,42,35,35,18,7,5,6,4)
Am = matrix(A, nrow = 43, ncol = 10)
pheatmap(Am, colorRampPalette(c("grey90", "purple", "black"))(1000),display_numbers = FALSE, border_color = NA, cluster_row = FALSE, cluster_col = FALSE,show_rownames = T,show_colnames = T, legend = TRUE)
B <- c(99,90,86,87,90,95,86,85,83,80,
83,85,84,79,57,37,27,66,83,80,
87,95,88,88,91,105,114,124,127,122,
114,100,104,83,73,69,71,72,74,86,
32,14,20,81,85,84,82,82,84,83,
83,82,80,79,81,82,90,82,79,89,
84,86,116,228,861,1130,1121,814,565,484,
415,348,278,207,149,436,188,86,74,77,
83,74,81,27,15,20,74,84,88,88,
87,84,84,91,97,86,102,92,84,81,
76,77,80,93,87,82,86,88,89,98,
107,106,104,97,95,97,93,90,90,84,
78,74,72,72,77,83,24,13,14,68,
80,82,87,88,82,81,81,84,85,86,
89,85,83,82,88,89,98,95,102,135,
142,87,89,110,101,93,92,90,92,92,
87,96,90,85,73,72,86,89,83,22,
13,18,65,82,81,81,81,83,82,82,
79,80,81,90,82,84,85,87,93,100,
111,140,357,1503,1935,1924,1193,662,466,377,
313,258,208,176,817,191,79,71,79,77,
83,94,26,14,18,62,84,81,83,83,
84,84,86,90,86,82,83,87,80,82,
81,78,85,98,114,192,719,1334,1817,1420,
821,562,458,408,362,280,212,1882,149,77,
75,73,81,81,84,24,16,17,72,86,
88,87,89,84,83,83,89,85,82,81,
85,81,78,82,82,83,84,92,255,1190,
1667,1742,1115,645,466,397,350,294,225,192,
1279,121,96,89,87,98,87,84,27,22,
20,69,84,93,96,94,90,93,89,92,
90,89,95,95,92,91,95,92,97,109,
121,151,299,530,767,734,543,382,282,254,
231,184,136,345,111,112,94,87,84,82,
92,25,15,15,111,84,88,93,89,95,
91,95,95,92,93,92,95,96,97,96,
96,108,107,106,116,186,294,380,367,233,
180,160,180,179,138,109,161,106,99,93,
92,100,93,102,28,15,21,71,87,90,
89,86,87,86,82,84,83,84,96,87,
84,84,83,83,89,124,145,293,1262,1813,
1956,1306,763,587,500,432,348,263,211,1076,
370,112,103,99,104,88,96,41,15,14)
Bm = matrix(B, nrow=43, ncol = 10)
pheatmap(Bm, colorRampPalette(c("grey90", "green", "darkgreen"))(1000),display_numbers = FALSE, border_color = NA, cluster_row = FALSE, cluster_col = FALSE,show_rownames = T,show_colnames = T, legend = TRUE)
C <- c(10,9,9,9,11,7,10,11,8,9,
11,12,23,53,136,203,208,160,58,26,
19,19,17,15,13,14,19,19,22,18,
27,33,27,21,16,19,14,14,13,9,
5,3,2,7,5,7,7,7,9,10,
9,8,9,11,11,12,16,23,32,29,
25,21,20,24,43,47,36,38,47,147,
150,81,67,40,25,62,26,17,15,13,
17,16,18,8,2,3,7,6,7,8,
8,9,9,16,11,20,28,14,12,30,
28,13,15,19,17,24,21,17,15,17,
17,22,23,23,24,27,23,21,21,18,
13,13,12,11,12,17,7,3,2,6,
7,6,8,9,8,7,10,10,18,20,
15,10,13,12,11,12,16,15,14,21,
46,39,24,25,43,73,77,120,152,107,
79,110,29,22,16,15,15,16,15,5,
3,3,6,6,6,6,7,7,6,6,
9,9,11,13,9,15,13,8,11,11,
10,12,12,14,15,17,14,14,19,18,
14,12,16,21,81,24,27,26,19,14,
13,15,5,3,3,6,6,5,7,6,
6,7,7,7,7,7,8,9,7,7,
8,8,9,14,14,12,8,7,15,31,
47,105,107,88,82,76,71,290,27,14,
14,10,10,10,9,5,4,4,5,6,
6,6,5,6,6,7,6,7,7,7,
6,8,7,7,6,7,7,7,12,33,
22,11,19,48,215,207,100,58,40,33,
194,20,19,20,17,12,7,8,4,3,
3,5,5,7,6,7,8,7,7,7,
8,9,7,7,7,7,8,9,11,10,
8,9,9,7,11,18,35,110,124,130,
122,82,52,118,16,19,16,10,6,8,
8,3,2,2,6,6,5,7,6,7,
7,8,7,10,10,8,9,10,9,8,
9,8,8,10,8,9,7,9,18,49,
136,127,128,203,163,71,118,11,8,8,
8,11,10,7,4,4,4,7,7,6,
7,6,4,5,6,7,7,6,6,5,
7,7,7,7,8,9,9,9,7,8,
10,22,50,210,212,105,74,43,31,139,
28,11,8,9,9,8,6,2,2,3)
Cm = matrix(C, nrow=43, ncol= 10)
pheatmap(Cm, colorRampPalette(c("grey90", "red", "darkred"))(1000),display_numbers = FALSE, border_color = NA, cluster_row = FALSE, cluster_col = FALSE,show_rownames = T,show_colnames = T, legend = TRUE)
#make a matrix from all three datasets
m <- matrix(c(Am, Bm, Cm),nrow = 43, ncol =30)
#order the matrix m, so you always have column 1 from A, column 1 from B, column 1 from C....
m <- m[, c(matrix(1:ncol(m), nrow = 3, byrow = T))]
#make a list with the colours to be used
mycols = c(colorRampPalette(c("grey90", "purple", "black"))(1000),colorRampPalette(c("grey90", "green", "darkgreen"))(1000),colorRampPalette(c("grey90", "red", "darkred"))(1000))
#if you want to use all colours, but not ordered
pheatmap(m, col = mycols, display_numbers = FALSE, border_color = NA, cluster_row = FALSE, cluster_col = FALSE,show_rownames = T,show_colnames = T, legend = TRUE)
could you reduce your dataset to a smaller reproducible example, please
@russhh This is a 4+ year old question that was bumped to main page by biostars automated process.
Plus this has a much better solution today: Use ComplexHeatmap.
Amen to that!