pheatmap 中的颜色缩放

问题描述

我为一个班级制作了这个相关矩阵的热图。我想修复颜色缩放,特别是针对感染状态。它选择的粉红色色调不仅与感染 tatus 相似,而且看起来与 hpi 相同。

enter image description here

pheatmap(t(correlation_matrix),clustering_distance_cols = "euclidean",show_colnames = TRUE,show_rownames = FALSE,main = "Correlation between Samples",cluster_cols = TRUE,cluster_rows = TRUE,annotation = dge_cpmlogtwo_df,)

这些是用于聚类的因素和水平。它们是样本 ID 的索引。它是 27 行 x 3 列。

> dge_cpmlogtwo_df
                hpi infection_status batch
SRR1346026  4 hours       Uninfected     A
SRR1346027  4 hours         Infected     A
SRR1346028  4 hours         Infected     B
SRR1346029  4 hours         Infected     C
SRR1346030  6 hours       Uninfected     A
SRR1346031  6 hours         Infected     A
SRR1346032  6 hours         Infected     B
SRR1346033  6 hours         Infected     C
SRR1346034 12 hours       Uninfected     A
SRR1346035 12 hours         Infected     A
SRR1346036 12 hours         Infected     B
SRR1346037 24 hours       Uninfected     A
SRR1346038 24 hours         Infected     A
SRR1346039 24 hours         Infected     B
SRR1346040 24 hours         Infected     C
SRR1346041 48 hours       Uninfected     D
SRR1346042 48 hours       Uninfected     A
SRR1346043 48 hours       Uninfected     C
SRR1346044 48 hours         Infected     D
SRR1346045 48 hours         Infected     D
SRR1346046 48 hours         Infected     A
SRR1346047 48 hours         Infected     C
SRR1346049 72 hours       Uninfected     E
SRR1346048 72 hours       Uninfected     D
SRR1346050 72 hours         Infected     D
SRR1346051 72 hours         Infected     D
SRR1346052 72 hours         Infected     E

这是相关矩阵变量。行和列是样本 ID。它是 27 行 x 27 列。

> correlation_matrix
           SRR1346026 SRR1346027 SRR1346028 SRR1346029 SRR1346030 SRR1346031 SRR1346032 SRR1346033 SRR1346034 SRR1346035
SRR1346026  1.0000000  0.9767772  0.9215334  0.9605981  0.9934820  0.9771208  0.9669951  0.9679269  0.9887120  0.9708488
SRR1346027  0.9767772  1.0000000  0.9501930  0.9836713  0.9748577  0.9950659  0.9904760  0.9888933  0.9661780  0.9859585
SRR1346028  0.9215334  0.9501930  1.0000000  0.9608120  0.9234477  0.9496890  0.9592347  0.9492721  0.9195782  0.9558195
SRR1346029  0.9605981  0.9836713  0.9608120  1.0000000  0.9605030  0.9790251  0.9770097  0.9887397  0.9555135  0.9765122
SRR1346030  0.9934820  0.9748577  0.9234477  0.9605030  1.0000000  0.9779315  0.9672352  0.9675250  0.9918194  0.9740802
SRR1346031  0.9771208  0.9950659  0.9496890  0.9790251  0.9779315  1.0000000  0.9935314  0.9885312  0.9720795  0.9930384
SRR1346032  0.9669951  0.9904760  0.9592347  0.9770097  0.9672352  0.9935314  1.0000000  0.9852781  0.9615259  0.9899109
SRR1346033  0.9679269  0.9888933  0.9492721  0.9887397  0.9675250  0.9885312  0.9852781  1.0000000  0.9603751  0.9826989
SRR1346034  0.9887120  0.9661780  0.9195782  0.9555135  0.9918194  0.9720795  0.9615259  0.9603751  1.0000000  0.9722691
SRR1346035  0.9708488  0.9859585  0.9558195  0.9765122  0.9740802  0.9930384  0.9899109  0.9826989  0.9722691  1.0000000
SRR1346036  0.9627217  0.9833644  0.9416681  0.9673651  0.9630103  0.9889793  0.9910965  0.9780583  0.9593498  0.9898640
SRR1346037  0.9722947  0.9479767  0.9039104  0.9403006  0.9755460  0.9564776  0.9436444  0.9437803  0.9856064  0.9574448
SRR1346038  0.9540688  0.9678848  0.9482641  0.9651477  0.9569638  0.9757942  0.9749888  0.9679161  0.9603866  0.9850897
SRR1346039  0.9438566  0.9636203  0.9287476  0.9537760  0.9457019  0.9715359  0.9734664  0.9615520  0.9474412  0.9781649
SRR1346040  0.9509221  0.9648452  0.9160709  0.9635869  0.9529032  0.9711931  0.9661687  0.9721338  0.9550494  0.9733841
SRR1346041  0.9724891  0.9487735  0.9072796  0.9470519  0.9758698  0.9567595  0.9438975  0.9505854  0.9834864  0.9585096
SRR1346042  0.9283870  0.9040806  0.8743213  0.9048192  0.9341621  0.9162452  0.9036906  0.9027526  0.9521506  0.9217687
SRR1346043  0.8942260  0.8694030  0.8104232  0.8726564  0.8978979  0.8802026  0.8630856  0.8798497  0.9153946  0.8787575
SRR1346044  0.9299930  0.9567852  0.9240081  0.9544773  0.9339745  0.9658739  0.9628878  0.9611494  0.9392413  0.9694265
SRR1346045  0.9292768  0.9396396  0.9011450  0.9392302  0.9341114  0.9511862  0.9428545  0.9441111  0.9453077  0.9561207
SRR1346046  0.9186613  0.9370952  0.8995979  0.9305964  0.9220700  0.9486054  0.9446127  0.9365340  0.9316616  0.9554006
SRR1346047  0.8859886  0.9046282  0.8599083  0.9067265  0.8886075  0.9145193  0.9083829  0.9155067  0.8979748  0.9199795
SRR1346049  0.8929932  0.8708984  0.8074955  0.8669050  0.8960592  0.8810787  0.8665217  0.8750108  0.9115385  0.8770615
SRR1346048  0.9158966  0.8923403  0.8506703  0.8951668  0.9202891  0.9044918  0.8901567  0.8974785  0.9381094  0.9070072
SRR1346050  0.8522185  0.8854120  0.8628482  0.8875369  0.8554240  0.8962719  0.8977277  0.8932761  0.8653457  0.9049153
SRR1346051  0.8556003  0.8734048  0.8466184  0.8791925  0.8611161  0.8864400  0.8809600  0.8826160  0.8745547  0.8965798
SRR1346052  0.8837287  0.8743288  0.8155009  0.8691975  0.8847602  0.8861122  0.8745943  0.8809658  0.8979302  0.8885524
           SRR1346036 SRR1346037 SRR1346038 SRR1346039 SRR1346040 SRR1346041 SRR1346042 SRR1346043 SRR1346044 SRR1346045
SRR1346026  0.9627217  0.9722947  0.9540688  0.9438566  0.9509221  0.9724891  0.9283870  0.8942260  0.9299930  0.9292768
SRR1346027  0.9833644  0.9479767  0.9678848  0.9636203  0.9648452  0.9487735  0.9040806  0.8694030  0.9567852  0.9396396
SRR1346028  0.9416681  0.9039104  0.9482641  0.9287476  0.9160709  0.9072796  0.8743213  0.8104232  0.9240081  0.9011450
SRR1346029  0.9673651  0.9403006  0.9651477  0.9537760  0.9635869  0.9470519  0.9048192  0.8726564  0.9544773  0.9392302
SRR1346030  0.9630103  0.9755460  0.9569638  0.9457019  0.9529032  0.9758698  0.9341621  0.8978979  0.9339745  0.9341114
SRR1346031  0.9889793  0.9564776  0.9757942  0.9715359  0.9711931  0.9567595  0.9162452  0.8802026  0.9658739  0.9511862
SRR1346032  0.9910965  0.9436444  0.9749888  0.9734664  0.9661687  0.9438975  0.9036906  0.8630856  0.9628878  0.9428545
SRR1346033  0.9780583  0.9437803  0.9679161  0.9615520  0.9721338  0.9505854  0.9027526  0.8798497  0.9611494  0.9441111
SRR1346034  0.9593498  0.9856064  0.9603866  0.9474412  0.9550494  0.9834864  0.9521506  0.9153946  0.9392413  0.9453077
SRR1346035  0.9898640  0.9574448  0.9850897  0.9781649  0.9733841  0.9585096  0.9217687  0.8787575  0.9694265  0.9561207
SRR1346036  1.0000000  0.9444743  0.9802628  0.9842896  0.9757149  0.9433758  0.9030998  0.8682346  0.9679331  0.9497857
SRR1346037  0.9444743  1.0000000  0.9567400  0.9457821  0.9545563  0.9909163  0.9772462  0.9484518  0.9463379  0.9602798
SRR1346038  0.9802628  0.9567400  1.0000000  0.9901290  0.9838688  0.9571909  0.9311056  0.8874208  0.9776753  0.9711869
SRR1346039  0.9842896  0.9457821  0.9901290  1.0000000  0.9847597  0.9440904  0.9167827  0.8820776  0.9767189  0.9664030
SRR1346040  0.9757149  0.9545563  0.9838688  0.9847597  1.0000000  0.9588967  0.9267822  0.9109268  0.9800535  0.9775649
SRR1346041  0.9433758  0.9909163  0.9571909  0.9440904  0.9588967  1.0000000  0.9720991  0.9478141  0.9483049  0.9616441
SRR1346042  0.9030998  0.9772462  0.9311056  0.9167827  0.9267822  0.9720991  1.0000000  0.9716453  0.9313119  0.9586718
SRR1346043  0.8682346  0.9484518  0.8874208  0.8820776  0.9109268  0.9478141  0.9716453  1.0000000  0.9094145  0.9423281
SRR1346044  0.9679331  0.9463379  0.9776753  0.9767189  0.9800535  0.9483049  0.9313119  0.9094145  1.0000000  0.9850759
SRR1346045  0.9497857  0.9602798  0.9711869  0.9664030  0.9775649  0.9616441  0.9586718  0.9423281  0.9850759  1.0000000
SRR1346046  0.9570618  0.9452787  0.9783722  0.9828725  0.9785027  0.9423506  0.9391646  0.9141188  0.9813525  0.9847062
SRR1346047  0.9239850  0.9177985  0.9491444  0.9571795  0.9661307  0.9200096  0.9172099  0.9217258  0.9624689  0.9716592
SRR1346049  0.8719634  0.9411944  0.8802862  0.8805065  0.9033869  0.9370325  0.9588678  0.9807222  0.9015430  0.9330923
SRR1346048  0.8916851  0.9662192  0.9165115  0.9058329  0.9255317  0.9669431  0.9867553  0.9854111  0.9288403  0.9585808
SRR1346050  0.9097404  0.8865398  0.9349284  0.9463247  0.9401013  0.8876525  0.8946442  0.8878057  0.9566031  0.9545210
SRR1346051  0.8932478  0.9029199  0.9295733  0.9353155  0.9369975  0.9033215  0.9212103  0.9200577  0.9440006  0.9628043
SRR1346052  0.8903102  0.9240956  0.9131324  0.9200739  0.9311645  0.9230041  0.9341477  0.9477148  0.9191593  0.9494846
           SRR1346046 SRR1346047 SRR1346049 SRR1346048 SRR1346050 SRR1346051 SRR1346052
SRR1346026  0.9186613  0.8859886  0.8929932  0.9158966  0.8522185  0.8556003  0.8837287
SRR1346027  0.9370952  0.9046282  0.8708984  0.8923403  0.8854120  0.8734048  0.8743288
SRR1346028  0.8995979  0.8599083  0.8074955  0.8506703  0.8628482  0.8466184  0.8155009
SRR1346029  0.9305964  0.9067265  0.8669050  0.8951668  0.8875369  0.8791925  0.8691975
SRR1346030  0.9220700  0.8886075  0.8960592  0.9202891  0.8554240  0.8611161  0.8847602
SRR1346031  0.9486054  0.9145193  0.8810787  0.9044918  0.8962719  0.8864400  0.8861122
SRR1346032  0.9446127  0.9083829  0.8665217  0.8901567  0.8977277  0.8809600  0.8745943
SRR1346033  0.9365340  0.9155067  0.8750108  0.8974785  0.8932761  0.8826160  0.8809658
SRR1346034  0.9316616  0.8979748  0.9115385  0.9381094  0.8653457  0.8745547  0.8979302
SRR1346035  0.9554006  0.9199795  0.8770615  0.9070072  0.9049153  0.8965798  0.8885524
SRR1346036  0.9570618  0.9239850  0.8719634  0.8916851  0.9097404  0.8932478  0.8903102
SRR1346037  0.9452787  0.9177985  0.9411944  0.9662192  0.8865398  0.9029199  0.9240956
SRR1346038  0.9783722  0.9491444  0.8802862  0.9165115  0.9349284  0.9295733  0.9131324
SRR1346039  0.9828725  0.9571795  0.8805065  0.9058329  0.9463247  0.9353155  0.9200739
SRR1346040  0.9785027  0.9661307  0.9033869  0.9255317  0.9401013  0.9369975  0.9311645
SRR1346041  0.9423506  0.9200096  0.9370325  0.9669431  0.8876525  0.9033215  0.9230041
SRR1346042  0.9391646  0.9172099  0.9588678  0.9867553  0.8946442  0.9212103  0.9341477
SRR1346043  0.9141188  0.9217258  0.9807222  0.9854111  0.8878057  0.9200577  0.9477148
SRR1346044  0.9813525  0.9624689  0.9015430  0.9288403  0.9566031  0.9440006  0.9191593
SRR1346045  0.9847062  0.9716592  0.9330923  0.9585808  0.9545210  0.9628043  0.9494846
SRR1346046  1.0000000  0.9816146  0.9074750  0.9348416  0.9708529  0.9698043  0.9483167
SRR1346047  0.9816146  1.0000000  0.9087224  0.9276567  0.9781539  0.9811185  0.9605999
SRR1346049  0.9074750  0.9087224  1.0000000  0.9719494  0.8810974  0.9104092  0.9587756
SRR1346048  0.9348416  0.9276567  0.9719494  1.0000000  0.9015451  0.9302373  0.9465731
SRR1346050  0.9708529  0.9781539  0.8810974  0.9015451  1.0000000  0.9798391  0.9349487
SRR1346051  0.9698043  0.9811185  0.9104092  0.9302373  0.9798391  1.0000000  0.9599284
SRR1346052  0.9483167  0.9605999  0.9587756  0.9465731  0.9349487  0.9599284  1.0000000

解决方法

From the help page of the pheatmap function

annotation_colors

用于手动指定 annotation_row 和 annotation_col 轨道颜色的列表。可以只为某些特征定义颜色。查看示例以了解详细信息。

示例


# Specify colors
ann_colors = list(
    Time = c("white","firebrick"),CellType = c(CT1 = "#1B9E77",CT2 = "#D95F02"),GeneClass = c(Path1 = "#7570B3",Path2 = "#E7298A",Path3 = "#66A61E")
)

pheatmap(test,annotation_col = annotation_col,annotation_colors = ann_colors,main = "Title")

在您的情况下,我猜 infection_status 可能是黑色/白色,hpi 可能是连续的以指示时间的流逝,而 batch 只是保留为默认值。

annot_cols = list(
    'infection_status' = c('Uninfected'='#ffffff','Infected'='#000000'),'hpi' = setNames(scales::viridis_pal(length(unique(dge_cpmlogtwo_df$hpi))),nm = unique(dge_cpmlogtwo_df$hpi))
)


pheatmap(t(correlation_matrix),clustering_distance_cols = "euclidean",show_colnames = TRUE,show_rownames = FALSE,main = "Correlation between Samples",cluster_cols = TRUE,cluster_rows = TRUE,annotation_col = dge_cpmlogtwo_df,# annotation is deprecated
         annotation_colors = annot_cols
         )

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...