作者:Zuguang Gu
翻译:Steven Shen
原文:https://jokergoo.github.io/ComplexHeatmap-reference/book/a-single-heatmap.html#plot-the-heatmap



2.11 绘制热图

2.11 Plot the heatmap
**

Heatmap() function actually is only a constructor, which means it only puts all the data and configurations into the object in the Heatmap class. The clustering will only be performed when the draw() method is called. Under interactive mode (e.g. the interactive R terminal where you can type your R code line by line), directly calling Heatmap() without returning to any object prints the object and the print method (or the S4 show() method) for the Heatmap class object calls draw() internally. So if you type Heatmap(...) in your R terminal, it looks like it is a plotting function like plot(), you need to be aware of that it is actually not true and in the following cases you might see nothing plotted.

  • you put Heatmap(...) inside a function,
  • you put Heatmap(...) in a code chunk like for or if-else
  • you put Heatmap(...) in an Rscript and you run it under command line.

Heatmap() 函数实际上只是一个构造函数,这意味着它只将所有数据和配置放入 Heatmap 类的对象中。只有在调用 draw() 方法时才会执行聚类。在交互模式下(例如,在您可以逐行键入 R 代码的交互式 R 终端),directly calling Heatmap() without returning to any object prints the object and the print method (or the S4 show() method) for the Heatmap class object calls draw() internally. 因此,如果您在 R 终端中键入 Heatmap(...) ,它看起来像是一个绘图函数,如 plot() ,您需要知道它实际上不是真的,在以下情况下您可能看不到任何绘图。

  • 你把 Heatmap(...) 放在一个函数中;
  • 你把 Heatmap(...) 放在像 forif-else 这样的代码块中
  • 你把 Heatmap(...) 放在一个 Rscript 中,然后在命令行下运行它。

The reason is in above three cases, the show() method WILL NOT be called and thus draw() method is not executed either. So, to make the plot, you need to call draw() explicitly: draw(Heatmap(...)) or:

原因是在上述三种情况下,不会调用 show() 方法,因此也不会执行 draw() 方法。因此,要制作绘图,您需要显式调用 draw(Heatmap(...)) 或:

  1. # code only for demonstration
  2. ht = Heatmap(...)
  3. draw(ht)

The draw() function actually is applied to a list of heatmaps in HeatmapList class. The draw() method for the single Heatmap class constructs a HeatmapList with only one heatmap and call draw() method of the HeatmapList class. The draw() function accpets a lot of more arguments which e.g. controls the legends. It will be discussed in Chapter 4.

draw() 函数实际上应用于 HeatmapList 类中的热图列表。单个 Heatmap 类的 draw() 方法构造一个只有一个热图的 HeatmapList ,并调用 HeatmapList 类的 draw() 方法。 draw() 函数会接受更多的参数,例如: 控制图例。它将在第 4 章中讨论。

  1. draw(ht, heatmap_legend_side, padding, ...)

——Update. 2019-07-08——