基于当前用于ngs实验和功能富集分析结果的可视化项目,我正在尝试使用R包heatmaply创建一个特定生物过程(行中的名称,以及列中特定的注释基因)的交互式热图图。 -该值本质上是log2倍数变化,可以是正值或负值,0表示特定基因与特定生物学机制之间不存在关联/关联:
dd <- read.table("bim.test.trial.txt",sep="\t",header = T,row.names=1)
head(dd)
regulation.of.defense.response.to.virus
Ifng 3.332965
Il6 0.000000
Havcr2 2.436155
Lgals9 2.058915
Tlr3 0.000000
Tlr9 0.000000
regulation.of.cell.adhesion alpha.beta.T.cell.differentiation
Ifng 3.332965 3.332965
Il6 3.994865 3.994865
Havcr2 2.436155 0.000000
Lgals9 2.058915 0.000000
Tlr3 0.000000 0.000000
Tlr9 0.000000 0.000000
...
heatmaply(t(dd),
fontsize_col = 7.5,
col = cool_warm(50),
scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(low = "blue", mid="white",high = "red", midpoint = 0, limits = c(-2, 2)),
main = 'Trial_test_heatmap')
# also a reproducible example:
set.seed(256)
xx2 <- matrix(rnorm(16),8,8)
range(xx2)
[1] -1.867392 1.654713
#first heatmap
heatmaply(xx2,
fontsize_col = 7.5,
col = cool_warm(50),
scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(low = "blue", mid="white",high = "red", midpoint = 0, limits = c(-1, 1)), main = 'Trial_test_heatmap')
# second
heatmaply(xx2,
fontsize_col = 7.5,
col = cool_warm(50),
scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(low = "blue", mid="white",high = "red", midpoint = 0, limits = c(-2, 2)), main = 'Trial_test_heatmap')
sessionInfo()
R version 3.5.0 (2018-04-23)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows >= 8 x64 (build 9200)
Matrix products: default
locale:
[1] LC_COLLATE=Greek_Greece.1253 LC_CTYPE=Greek_Greece.1253
[3] LC_MONETARY=Greek_Greece.1253 LC_NUMERIC=C
[5] LC_TIME=Greek_Greece.1253
attached base packages:
[1] grid stats graphics grDevices utils datasets methods
[8] base
other attached packages:
[1] heatmaply_0.15.2 viridis_0.5.1 viridisLite_0.3.0
[4] plotly_4.8.0 ggplot2_3.1.0 circlize_0.4.5
[7] ComplexHeatmap_1.20.0
loaded via a namespace (and not attached):
[1] httr_1.4.0 tidyr_0.8.2 jsonlite_1.6
[4] foreach_1.4.4 gtools_3.8.1 shiny_1.2.0
[7] assertthat_0.2.0 stats4_3.5.0 yaml_2.2.0
[10] robustbase_0.93-3 pillar_1.3.1 lattice_0.20-38
[13] glue_1.3.0 digest_0.6.18 promises_1.0.1
[16] RColorBrewer_1.1-2 colorspace_1.3-2 httpuv_1.4.5
[19] htmltools_0.3.6 plyr_1.8.4 pkgconfig_2.0.2
[22] GetoptLong_0.1.7 xtable_1.8-3 purrr_0.2.5
[25] mvtnorm_1.0-8 scales_1.0.0 webshot_0.5.1
[28] gdata_2.18.0 whisker_0.3-2 later_0.7.5
[31] tibble_1.4.2 withr_2.1.2 nnet_7.3-12
[34] lazyeval_0.2.1 mime_0.6 magrittr_1.5
[37] crayon_1.3.4 mclust_5.4.2 MASS_7.3-51.1
[40] gplots_3.0.1 class_7.3-14 Cairo_1.5-9
[43] tools_3.5.0 registry_0.5 data.table_1.11.8
[46] GlobalOptions_0.1.0 stringr_1.3.1 trimcluster_0.1-2.1
[49] kernlab_0.9-27 munsell_0.5.0 cluster_2.0.7-1
[52] fpc_2.1-11.1 bindrcpp_0.2.2 compiler_3.5.0
[55] caTools_1.17.1.1 rlang_0.3.0.1 iterators_1.0.10
[58] rstudioapi_0.8 rjson_0.2.20 htmlwidgets_1.3
[61] crosstalk_1.0.0 labeling_0.3 bitops_1.0-6
[64] gtable_0.2.0 codetools_0.2-15 flexmix_2.3-14
[67] TSP_1.1-6 reshape2_1.4.3 R6_2.3.0
[70] seriation_1.2-3 gridExtra_2.3 knitr_1.21
[73] prabclus_2.2-6 dplyr_0.7.8 bindr_0.1.1
[76] KernSmooth_2.23-15 dendextend_1.9.0 shape_1.4.4
[79] stringi_1.2.4 modeltools_0.2-22 Rcpp_1.0.0
[82] gclus_1.3.1 DEoptimR_1.0-8 tidyselect_0.2.5
[85] xfun_0.4 diptest_0.75-7
但是,如果您看到我附加的快照png图像,则热图体中的值0(即所需的中点)不会显示为白色,并且也不会显示白色,也有大量离散值,在许多基因中为零,它们以不同的颜色着色-在ggplot2-函数scale_fill_gradient2的下限中定义的蓝色是蓝色
因此,有一种方法可以解决此问题?并正确指定调色板的低端,中端和高端?
提前谢谢
Efstathios
答案 0 :(得分:1)
您的数据范围比颜色范围(-2至2)宽(> 2)。 我相信您在软件包中看到了一个错误。请在scale_fill_gradient_fun中使用包含所有数据的范围。例如:
heatmaply(t(dd),
fontsize_col = 7.5,
col = cool_warm(50),
scale_fill_gradient_fun = ggplot2::scale_fill_gradient2(low = "blue", mid="white",high = "red", midpoint = 0, limits = c(-4, 4)),
main = 'Trial_test_heatmap')