rstudio 中的 pheatmap 错误“维数不正确”
pheatmap in rstudio error" incorrect number of dimensions"
我有一个 3000 行和 53 列的大型基因和组织数据集。
当我尝试在 R 中使用 pheatmap
为少量列创建热图时,它是成功的。
但是当我尝试将 annotation_col
和带颜色条的行添加到热图中时,出现错误。
"Error in annotation_colors[[colnames(annotation)[i]]] : subscript
out of bounds"
任何帮助将不胜感激。
top<-as_tibble(transformed,rownames=NA)%>%
rownames_to_column("gene")%>%
mutate(variance=top_genes_var)%>%
arrange(desc(variance))%>%
head(n=6)
colors <- colorRampPalette( rev(brewer.pal(9, "Blues")) )(255)
anno <- data.frame(top$variance)
pheatmap(top[2:54],labels_row = top$gene,scale="row",
main="Heatmap", col=colors, border_color = "black",
cluster_cols = T, show_rownames = T,show_colnames = F,
annotation_row = anno)
这里是 top
数据框:
top <- structure(list(gene = c("IGKJ3", "IGKJ5", "IGHJ5", "AC053503.6",
"IGHJ3", "IGHJ6"), `Adipose - Subcutaneous` = c(3.76341157447001,
3.48864353985378, 0.923719678749389, -0.241611534520648,
1.10198617278574,
1.88791513563813), `Adipose - Visceral (Omentum)` = c(5.31903981556254,
5.10475598696226, 2.68032435684402, 0.0271540515037266, 2.99276843076892,
3.68706068833989), `Adrenal Gland` = c(2.27441076931784, 2.3769848882563,
-0.398113355021022, -6.64385618977472, -0.000577193462745523,
0.666756591884803), `Artery - Aorta` = c(5.02547181462118,
4.90544717873885,
2.63900057242433, 1.51551061996901, 2.63900057242433, 3.50589092972996
), `Artery - Coronary` = c(5.02635744696384, 5.23993261348524,
2.23786960086751, 2.68324729644458, 2.62363279110652, 3.38266725274504
), `Artery - Tibial` = c(1.40979822782842, 1.37517847958961,
-6.64385618977472, 4.4541758931858, -0.691522623405039,
0.0538064436957938
), Bladder = c(3.12234140752612, 2.19534759832222, 1.62293035092018,
5.91288933622996, 1.7583031771319, 1.39066768555967), `Brain - Amygdala`
= c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Anterior cingulate cortex (BA24)` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Caudate (basal ganglia)` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Cerebellar Hemisphere` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Cerebellum` = c(-6.64385618977472,
-0.408895094935221, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Cortex` = c(-6.64385618977472,
-0.725589230682162,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472
), `Brain - Frontal Cortex (BA9)` = c(-6.64385618977472,
-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472
), `Brain - Hippocampus` = c(-6.64385618977472, -6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472
), `Brain - Hypothalamus` = c(-6.64385618977472, -6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472
), `Brain - Nucleus accumbens (basal ganglia)` = c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Putamen (basal ganglia)` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Spinal cord (cervical c-1)` =
c(-6.64385618977472,
-0.210229022689942, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Substantia nigra` = c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Breast - Mammary Tissue` = c(5.76778719809436,
5.7733370484736, 3.13889636343532, -1.75901409597526, 3.249597036059,
3.48864353985378), `Cells - EBV-transformed lymphocytes` =
c(6.11811050560737,
5.77991629665499, 6.80296865100558, -6.64385618977472, 6.40207407351685,
9.25776496857139), `Cells - Transformed fibroblasts` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Cervix - Ectocervix` = c(6.73991559246805,
7.58616424593091, 4.55857377624063, 5.42054977211632, 3.89569039046369,
3.54361960839827), `Cervix - Endocervix` = c(7.46523987393246,
7.20662368996032, 4.42492208821069, 3.96993327469786, 3.4541758931858,
3.41818994794577), `Colon - Sigmoid` = c(2.55507989832666,
2.29160355803056,
-0.120294233717712, 6.64832162654502, -0.0909565868344218,
0.408168370708106
), `Colon - Transverse` = c(10.0161257705052, 10.5333394670573,
7.68866994120155, 4.39746072605472, 7.72253433227825, 7.98390566262789
), `Esophagus - Gastroesophageal Junction` = c(1.5358041382703,
0.874993638932967, -1.45858428418091, 6.07499772513591,
-6.64385618977472,
-0.524500012735049), `Esophagus - Mucosa` = c(6.76434084667018,
6.81390942507703, 3.99004721957379, 2.19755090741987, 3.74200621086674,
4.48992821940518), `Esophagus - Muscularis` = c(1.68795649404448,
1.39670752138398, -6.64385618977472, 6.12484506325342,
-0.494007475604962,
-0.118961924325956), `Fallopian Tube` = c(8.29098646472839,
7.84743324370703,
4.97039353791468, 5.78371855779037, 5.06565847093199, 5.65420637794429
), `Heart - Atrial Appendage` = c(1.37795663381011, 1.34993137336011,
-0.607352856035737, 4.94063660720115, -0.708160726742885,
-0.0197552951466102
), `Heart - Left Ventricle` = c(0.788268082866837, 0.855192407959154,
-1.608232280044, 4.44228003525258, -1.31724693876945, -0.722134242765121
), `Kidney - Cortex` = c(4.61235249875266, 4.27947129564447,
1.02147972741045, -6.64385618977472, 1.43135552157352, 2.2424500736777
), Liver = c(5.43362716708478, 5.47832471148503, 2.64454851724905,
-6.64385618977472, 3.05189409233429, 3.4867143730307), Lung =
c(8.70773873872454,
8.68723569410704, 6.40735275114004, 1.27202318906105, 6.61028665708102,
7.33637266078553), `Minor Salivary Gland` = c(10.994360508876,
11.1541915396377, 8.53336867091775, -6.64385618977472, 8.48506449776403,
9.04851412010032), `Muscle - Skeletal` = c(0.469365053704843,
0.404358194833311, -6.64385618977472, 3.10567807789454,
-6.64385618977472,
-1.13622009620412), `Nerve - Tibial` = c(3.5033487351675,
3.34411833452143,
0.280362489973778, -6.64385618977472, 0.406536670205172, 1.63296612490967
), Ovary = c(4.1407786557828, 3.51601514700366, 0.919149363287674,
2.31411643114067, 1.22342254993494, 1.87302570104647), Pancreas =
c(2.37795663381011,
2.36415216865035, 0.264236151043547, -6.64385618977472,
0.296897857700078,
0.566084490515467), Pituitary = c(3.03104224335857, 2.82761581382173,
0.153156788061421, -6.64385618977472, 0.491596594410448,
0.941106310946431
), Prostate = c(4.95628902658394, 4.50239425611126, 1.97489636376201,
5.64803395056383, 2.16365973836986, 2.79066779312473), `Skin - Not Sun
Exposed (Suprapubic)` = c(2.72268459807061,
2.53804145333366, -0.0944950568503844, 0.176322772640463,
0.0676387168753633,
0.519038609600059), `Skin - Sun Exposed (Lower leg)` =
c(1.59645813955899,
1.39999135066418, -6.64385618977472, 0.841570637395517,
-6.64385618977472,
-0.413499444718575), `Small Intestine - Terminal Ileum` =
c(9.9415025045676,
10.1202508395033, 7.56613016782684, 1.31614574229336, 7.8234309337855,
8.11118784632704), Spleen = c(11.7540565444049, 12.17602039241,
9.84472145432163, -1.84321509244564, 10.047819183561, 10.5783821268763
), Stomach = c(8.3884909283468, 8.33967188139037, 5.94825040944276,
1.83045816354108, 6.05712530427152, 6.63981097771678), Testis =
c(0.410341104614087,
0.500802053057158, -6.64385618977472, 0.0257375614136083,
-6.64385618977472,
-0.627939417667839), Thyroid = c(4.32876467228402, 3.98959318493877,
1.52054796810658, -0.186064929518683, 1.45101324294397, 2.40231288230197
), Uterus = c(4.17871464117544, 4.00270252037982, 1.11503324294624,
5.93969674069176, 1.35727047567956, 1.63412855752504), Vagina =
c(5.45779126025604,
5.25096157353322, 2.63063844605544, 4.39506279951758, 2.38708677001591,
3.3138262963904), `Whole Blood` = c(7.25276003230215, 7.23179718352995,
5.34624777408278, -6.64385618977472, 5.94953493301701, 6.40565206128037
), variance = c(32.8165594560773, 29.0279160512817, 26.9757442417602,
26.53715773112, 26.4120469464566, 25.7712090599316)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -6L))
您需要为 top
和 anno
定义相同的行名称:
library(pheatmap)
library(RColorBrewer)
colors <- colorRampPalette(rev(brewer.pal(9, "Blues")) )(255)
anno <- data.frame(Var=top$variance)
# Define the same row names for top and anno
rownames(top) <- top$gene
rownames(anno) <- top$gene
pheatmap(top[, -c(1,55)], labels_row = top$gene, scale="row",
main="Heatmap", col=colors, border_color = "black",
cluster_cols = T, show_rownames = T, show_colnames = F,
annotation_row = anno)
我有一个 3000 行和 53 列的大型基因和组织数据集。
当我尝试在 R 中使用 pheatmap
为少量列创建热图时,它是成功的。
但是当我尝试将 annotation_col
和带颜色条的行添加到热图中时,出现错误。
"Error in annotation_colors[[colnames(annotation)[i]]] : subscript out of bounds"
任何帮助将不胜感激。
top<-as_tibble(transformed,rownames=NA)%>%
rownames_to_column("gene")%>%
mutate(variance=top_genes_var)%>%
arrange(desc(variance))%>%
head(n=6)
colors <- colorRampPalette( rev(brewer.pal(9, "Blues")) )(255)
anno <- data.frame(top$variance)
pheatmap(top[2:54],labels_row = top$gene,scale="row",
main="Heatmap", col=colors, border_color = "black",
cluster_cols = T, show_rownames = T,show_colnames = F,
annotation_row = anno)
这里是 top
数据框:
top <- structure(list(gene = c("IGKJ3", "IGKJ5", "IGHJ5", "AC053503.6",
"IGHJ3", "IGHJ6"), `Adipose - Subcutaneous` = c(3.76341157447001,
3.48864353985378, 0.923719678749389, -0.241611534520648,
1.10198617278574,
1.88791513563813), `Adipose - Visceral (Omentum)` = c(5.31903981556254,
5.10475598696226, 2.68032435684402, 0.0271540515037266, 2.99276843076892,
3.68706068833989), `Adrenal Gland` = c(2.27441076931784, 2.3769848882563,
-0.398113355021022, -6.64385618977472, -0.000577193462745523,
0.666756591884803), `Artery - Aorta` = c(5.02547181462118,
4.90544717873885,
2.63900057242433, 1.51551061996901, 2.63900057242433, 3.50589092972996
), `Artery - Coronary` = c(5.02635744696384, 5.23993261348524,
2.23786960086751, 2.68324729644458, 2.62363279110652, 3.38266725274504
), `Artery - Tibial` = c(1.40979822782842, 1.37517847958961,
-6.64385618977472, 4.4541758931858, -0.691522623405039,
0.0538064436957938
), Bladder = c(3.12234140752612, 2.19534759832222, 1.62293035092018,
5.91288933622996, 1.7583031771319, 1.39066768555967), `Brain - Amygdala`
= c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Anterior cingulate cortex (BA24)` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Caudate (basal ganglia)` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Cerebellar Hemisphere` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Cerebellum` = c(-6.64385618977472,
-0.408895094935221, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Cortex` = c(-6.64385618977472,
-0.725589230682162,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472
), `Brain - Frontal Cortex (BA9)` = c(-6.64385618977472,
-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472
), `Brain - Hippocampus` = c(-6.64385618977472, -6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472
), `Brain - Hypothalamus` = c(-6.64385618977472, -6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472
), `Brain - Nucleus accumbens (basal ganglia)` = c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Putamen (basal ganglia)` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Spinal cord (cervical c-1)` =
c(-6.64385618977472,
-0.210229022689942, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Brain - Substantia nigra` = c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Breast - Mammary Tissue` = c(5.76778719809436,
5.7733370484736, 3.13889636343532, -1.75901409597526, 3.249597036059,
3.48864353985378), `Cells - EBV-transformed lymphocytes` =
c(6.11811050560737,
5.77991629665499, 6.80296865100558, -6.64385618977472, 6.40207407351685,
9.25776496857139), `Cells - Transformed fibroblasts` =
c(-6.64385618977472,
-6.64385618977472, -6.64385618977472, -6.64385618977472,
-6.64385618977472,
-6.64385618977472), `Cervix - Ectocervix` = c(6.73991559246805,
7.58616424593091, 4.55857377624063, 5.42054977211632, 3.89569039046369,
3.54361960839827), `Cervix - Endocervix` = c(7.46523987393246,
7.20662368996032, 4.42492208821069, 3.96993327469786, 3.4541758931858,
3.41818994794577), `Colon - Sigmoid` = c(2.55507989832666,
2.29160355803056,
-0.120294233717712, 6.64832162654502, -0.0909565868344218,
0.408168370708106
), `Colon - Transverse` = c(10.0161257705052, 10.5333394670573,
7.68866994120155, 4.39746072605472, 7.72253433227825, 7.98390566262789
), `Esophagus - Gastroesophageal Junction` = c(1.5358041382703,
0.874993638932967, -1.45858428418091, 6.07499772513591,
-6.64385618977472,
-0.524500012735049), `Esophagus - Mucosa` = c(6.76434084667018,
6.81390942507703, 3.99004721957379, 2.19755090741987, 3.74200621086674,
4.48992821940518), `Esophagus - Muscularis` = c(1.68795649404448,
1.39670752138398, -6.64385618977472, 6.12484506325342,
-0.494007475604962,
-0.118961924325956), `Fallopian Tube` = c(8.29098646472839,
7.84743324370703,
4.97039353791468, 5.78371855779037, 5.06565847093199, 5.65420637794429
), `Heart - Atrial Appendage` = c(1.37795663381011, 1.34993137336011,
-0.607352856035737, 4.94063660720115, -0.708160726742885,
-0.0197552951466102
), `Heart - Left Ventricle` = c(0.788268082866837, 0.855192407959154,
-1.608232280044, 4.44228003525258, -1.31724693876945, -0.722134242765121
), `Kidney - Cortex` = c(4.61235249875266, 4.27947129564447,
1.02147972741045, -6.64385618977472, 1.43135552157352, 2.2424500736777
), Liver = c(5.43362716708478, 5.47832471148503, 2.64454851724905,
-6.64385618977472, 3.05189409233429, 3.4867143730307), Lung =
c(8.70773873872454,
8.68723569410704, 6.40735275114004, 1.27202318906105, 6.61028665708102,
7.33637266078553), `Minor Salivary Gland` = c(10.994360508876,
11.1541915396377, 8.53336867091775, -6.64385618977472, 8.48506449776403,
9.04851412010032), `Muscle - Skeletal` = c(0.469365053704843,
0.404358194833311, -6.64385618977472, 3.10567807789454,
-6.64385618977472,
-1.13622009620412), `Nerve - Tibial` = c(3.5033487351675,
3.34411833452143,
0.280362489973778, -6.64385618977472, 0.406536670205172, 1.63296612490967
), Ovary = c(4.1407786557828, 3.51601514700366, 0.919149363287674,
2.31411643114067, 1.22342254993494, 1.87302570104647), Pancreas =
c(2.37795663381011,
2.36415216865035, 0.264236151043547, -6.64385618977472,
0.296897857700078,
0.566084490515467), Pituitary = c(3.03104224335857, 2.82761581382173,
0.153156788061421, -6.64385618977472, 0.491596594410448,
0.941106310946431
), Prostate = c(4.95628902658394, 4.50239425611126, 1.97489636376201,
5.64803395056383, 2.16365973836986, 2.79066779312473), `Skin - Not Sun
Exposed (Suprapubic)` = c(2.72268459807061,
2.53804145333366, -0.0944950568503844, 0.176322772640463,
0.0676387168753633,
0.519038609600059), `Skin - Sun Exposed (Lower leg)` =
c(1.59645813955899,
1.39999135066418, -6.64385618977472, 0.841570637395517,
-6.64385618977472,
-0.413499444718575), `Small Intestine - Terminal Ileum` =
c(9.9415025045676,
10.1202508395033, 7.56613016782684, 1.31614574229336, 7.8234309337855,
8.11118784632704), Spleen = c(11.7540565444049, 12.17602039241,
9.84472145432163, -1.84321509244564, 10.047819183561, 10.5783821268763
), Stomach = c(8.3884909283468, 8.33967188139037, 5.94825040944276,
1.83045816354108, 6.05712530427152, 6.63981097771678), Testis =
c(0.410341104614087,
0.500802053057158, -6.64385618977472, 0.0257375614136083,
-6.64385618977472,
-0.627939417667839), Thyroid = c(4.32876467228402, 3.98959318493877,
1.52054796810658, -0.186064929518683, 1.45101324294397, 2.40231288230197
), Uterus = c(4.17871464117544, 4.00270252037982, 1.11503324294624,
5.93969674069176, 1.35727047567956, 1.63412855752504), Vagina =
c(5.45779126025604,
5.25096157353322, 2.63063844605544, 4.39506279951758, 2.38708677001591,
3.3138262963904), `Whole Blood` = c(7.25276003230215, 7.23179718352995,
5.34624777408278, -6.64385618977472, 5.94953493301701, 6.40565206128037
), variance = c(32.8165594560773, 29.0279160512817, 26.9757442417602,
26.53715773112, 26.4120469464566, 25.7712090599316)), class = c("tbl_df",
"tbl", "data.frame"), row.names = c(NA, -6L))
您需要为 top
和 anno
定义相同的行名称:
library(pheatmap)
library(RColorBrewer)
colors <- colorRampPalette(rev(brewer.pal(9, "Blues")) )(255)
anno <- data.frame(Var=top$variance)
# Define the same row names for top and anno
rownames(top) <- top$gene
rownames(anno) <- top$gene
pheatmap(top[, -c(1,55)], labels_row = top$gene, scale="row",
main="Heatmap", col=colors, border_color = "black",
cluster_cols = T, show_rownames = T, show_colnames = F,
annotation_row = anno)