在ComplexHeatmap中更改图例的顺序

问题描述

交叉发布: issues/557

我找不到在ComplexHeatmap中更改图例顺序的解决方案。

示例

library(ComplexHeatmap)

set.seed(100)

ha <- HeatmapAnnotation(foo = rep(c("gr1","gr2"),each = 5),annotation_label = c("col_an"))

ra <- HeatmapAnnotation(pt = rep(letters[1:2],which = "row",annotation_label = c("row_an"))

Heatmap(matrix(rnorm(100),10),name = "mat",top_annotation = ha,left_annotation = ra)

enter image description here

问题:如何按照从上到下的顺序排列图例?

  1. col_an
  2. row_an
  3. mat

SessionInfo

xfun::session_info()
R version 4.0.2 (2020-06-22)
Platform: x86_64-apple-darwin17.0 (64-bit)
Running under: macOS Mojave 10.14.6,RStudio 1.3.1056

Locale: en_US.UTF-8 / en_US.UTF-8 / en_US.UTF-8 / C / en_US.UTF-8 / en_US.UTF-8

Package version:
  assertthat_0.2.1     backports_1.1.8      base64enc_0.1.3      BiocGenerics_0.34.0  circlize_0.4.10     
  cli_2.0.2            clue_0.3-57          cluster_2.1.0        colorspace_1.4-1     compiler_4.0.2      
  ComplexHeatmap_2.5.4 crayon_1.3.4         curl_4.3             digest_0.6.25        ellipsis_0.3.1      
  evaluate_0.14        fansi_0.4.1          GetoptLong_1.0.2     GlobalOptions_0.1.2  glue_1.4.1          
  graphics_4.0.2       grDevices_4.0.2      grid_4.0.2           highr_0.8            htmltools_0.5.0     
  IRanges_2.22.2       jsonlite_1.7.0       knitr_1.29           lifecycle_0.2.0      magick_2.4.0        
  magrittr_1.5         markdown_1.1         methods_4.0.2        mime_0.9             parallel_4.0.2      
  pillar_1.4.6         pkgconfig_2.0.3      png_0.1-7            purrr_0.3.4          R.cache_0.14.0      
  R.methodsS3_1.8.0    R.oo_1.23.0          R.utils_2.9.2        RColorBrewer_1.1-2   Rcpp_1.0.5          
  rematch2_2.1.2       rjson_0.2.20         rlang_0.4.7          rmarkdown_2.3        rprojroot_1.3.2     
  rstudioapi_0.11      S4Vectors_0.26.1     shape_1.4.4          stats_4.0.2          stats4_4.0.2        
  stringi_1.4.6        stringr_1.4.0        styler_1.3.2         tibble_3.0.3         tinytex_0.25        
  tools_4.0.2          utf8_1.1.4           utils_4.0.2          vctrs_0.3.2          withr_2.2.0         
  xfun_0.16  

解决方法

这是作者提供的解决方案:

set.seed(100)

ha <- HeatmapAnnotation(foo = rep(c("gr1","gr2"),each = 5),annotation_label = c("col_an"),annotation_name_side = "left")
ra <- HeatmapAnnotation(pt = rep(letters[1:2],which = "row",annotation_label = c("row_an"))

ht = ha %v% Heatmap(matrix(rnorm(100),10),name = "mat",left_annotation = ra)
draw(ht,merge_legend = TRUE,column_dend_side = "top")

https://github.com/jokergoo/ComplexHeatmap/issues/557#issuecomment-673404750

相关问答

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