作者:Zuguang Gu8
    编译:Steven Shen
    原文:Change parameters globally


    ht_opt() is an option function which controls some parameters globally. You can set some parameters for all heatmaps/annotations simultaneously by this global function. Please note you should put it before your heatmap code and reset all option values after drawing the heatmaps to get rid of affecting next heatmap.

    1. ht_opt
    2. ## Option Value
    3. ## heatmap_row_names_gp NULL
    4. ## heatmap_column_names_gp NULL
    5. ## heatmap_row_title_gp NULL
    6. ## heatmap_column_title_gp NULL
    7. ## legend_title_gp NULL
    8. ## legend_title_position NULL
    9. ## legend_labels_gp NULL
    10. ## legend_grid_height NULL
    11. ## legend_grid_width NULL
    12. ## legend_border NULL
    13. ## heatmap_border NULL
    14. ## annotation_border NULL
    15. ## fast_hclust FALSE
    16. ## show_parent_dend_line TRUE
    17. ## verbose FALSE
    18. ## show_vp FALSE
    19. ## simple_anno_size 5mm
    20. ## DENDROGRAM_PADDING 0.5mm
    21. ## DIMNAME_PADDING 1mm
    22. ## TITLE_PADDING 2.5mm
    23. ## COLUMN_ANNO_PADDING 1mm
    24. ## ROW_ANNO_PADDING 1mm

    There are following parameters to control all heatmaps:

    • heatmap_row_names_gp: set row_names_gp in all Heatmap().
    • heatmap_column_names_gp: set column_names_gp in all Heatmap().
    • heatmap_row_title_gp: set row_title_gp in all Heatmap().
    • heatmap_column_title_gp: set column_title_gp in all Heatmap().
    • heatmap_border: set border in all Heatmap().

    Following parameters control the legends:

    • legend_title_gp: set title_gp in all heatmap legends and annotation legends.
    • legend_title_position: set title_position in all heatmap legends and annotation legends.
    • legend_labels_gp: set labels_gp in all heatmap legends and annotation legends.
    • legend_grid_width: set grid_width in all heatmap legends and annotation legends.
    • legend_grid_height: set grid_height in all heatmap legends and annotation legends.
    • legend_border: set border in all heatmap legends and annotation legends.

    Following parameters control heatmap annotations:

    • annotation_border: set border in all HeatmapAnnotation().
    • anno_simple_size: set size for the simple annotation.

    Following parameters control the space between heatmap components:

    • DENDROGRAM_PADDING: space bewteen dendrograms and heatmap body.
    • DIMNAME_PADDING: space between row/column names and heatmap body.
    • TITLE_PADDING: space between row/column titles and heatmap body.
    • COLUMN_ANNO_PADDING: space between column annotations and heatmap body.
    • ROW_ANNO_PADDING: space between row annotations and heatmap body.

    Other parameters:

    • fast_hclust: whether use fastcluster::hclust() to speed up clustering?
    • show_parent_dend_line: when heatmap is split, whether to add a dashed line to mark parent dendrogram and children dendrograms?

    You can get or set option values by the traditional way (like base::options()) or by $ operator:

    1. ht_opt("heatmap_row_names_gp")
    2. ht_opt$heatmap_row_names_gp
    3. # to set option values
    4. ht_opt("heatmap_row_names_gp" = gpar(fontsize = 8))
    5. ht_opt$heatmap_row_names_gp = gpar(fontsize = 8)

    Reset to the default values by:

    1. ht_opt(RESET = TRUE)

    Following example shows to control some graphic parameters globally.

    1. ht_opt(heatmap_column_names_gp = gpar(fontface = "italic"),
    2. heatmap_column_title_gp = gpar(fontsize = 10),
    3. legend_border = "black",
    4. heatmap_border = TRUE,
    5. annotation_border = TRUE
    6. )
    7. ht1 = Heatmap(mat1, name = "ht1", column_title = "Heatmap 1",
    8. top_annotation = HeatmapAnnotation(foo = 1:10))
    9. ht2 = Heatmap(mat2, name = "ht2", column_title = "Heatmap 2",
    10. top_annotation = HeatmapAnnotation(bar = 1:10))
    11. ht1 + ht2

    4.13 更改全局参数 - 图1

    1. ht_opt(RESET = TRUE)

    These global parameters can also be set in the draw() function to temporarily change the global parameters, and they are reset back after the plot is made. Please check the help page of draw,HeatmapList-method.