作者: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 theHeatmap
class. The clustering will only be performed when thedraw()
method is called. Under interactive mode (e.g. the interactive R terminal where you can type your R code line by line), directly callingHeatmap()
without returning to any object prints the object and the print method (or the S4show()
method) for theHeatmap
class object callsdraw()
internally. So if you typeHeatmap(...)
in your R terminal, it looks like it is a plotting function likeplot()
, 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 likefor
orif-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(...)
放在像for
或if-else
这样的代码块中 - 你把
Heatmap(...)
放在一个 Rscript 中,然后在命令行下运行它。
The reason is in above three cases, the
show()
method WILL NOT be called and thusdraw()
method is not executed either. So, to make the plot, you need to calldraw()
explicitly:draw(Heatmap(...))
or:
原因是在上述三种情况下,不会调用 show()
方法,因此也不会执行 draw()
方法。因此,要制作绘图,您需要显式调用 draw(Heatmap(...))
或:
# code only for demonstration
ht = Heatmap(...)
draw(ht)
The
draw()
function actually is applied to a list of heatmaps inHeatmapList
class. Thedraw()
method for the singleHeatmap
class constructs aHeatmapList
with only one heatmap and calldraw()
method of theHeatmapList
class. Thedraw()
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 章中讨论。
draw(ht, heatmap_legend_side, padding, ...)
——Update. 2019-07-08——