我正在尝试在函数调用graphics::rect的一行周围添加矩形框(即),heatmap如下所示:
stats::heatmap(matrix(data = rnorm(25),nrow = 5,ncol = 5),Colv = NA,scale = "none")
Run Code Online (Sandbox Code Playgroud)
为了确定参数,rect我需要能够自动检索绘制的热图的 xlim 和 ylim (不是侧面的树状图),但我不知道该怎么做..限制似乎并不存在为 1:5(对于本例)。
知道在哪里放置角度的技巧rect是获得正确的用户坐标。不幸的是,par("usr")(我最初的猜测)返回c(0, 1, 0, 1),没有帮助。然而,我通过阅读最后的“注释”中的内容找到了为什么会出现这种情况的线索?heatmap
\xe2\x80\x98heatmap()\xe2\x80\x99 uses layout and draws the image in the lower right\n corner of a 2x2 layout. Consequentially, it can *not* be used in\n a multi column/row layout, i.e., when \xe2\x80\x98par(mfrow = *)\xe2\x80\x99 or \xe2\x80\x98(mfcol\n = *)\xe2\x80\x99 has been called.\nRun Code Online (Sandbox Code Playgroud)\n这意味着在整个图完成后我们无法分解子图的用户坐标。然而......在同一个帮助页面中,我们看到
\nadd.expr: expression that will be evaluated after the call to image.\n Can be used to add components to the plot.\nRun Code Online (Sandbox Code Playgroud)\n我相信“调用图像”意味着实际的矩阵颜色图。
\n所以我尝试了这个:
\n \xe2\x80\x98heatmap()\xe2\x80\x99 uses layout and draws the image in the lower right\n corner of a 2x2 layout. Consequentially, it can *not* be used in\n a multi column/row layout, i.e., when \xe2\x80\x98par(mfrow = *)\xe2\x80\x99 or \xe2\x80\x98(mfcol\n = *)\xe2\x80\x99 has been called.\nRun Code Online (Sandbox Code Playgroud)\n好的,我们需要将您添加rect到通话中add.expr,坐标很直观。
add.expr: expression that will be evaluated after the call to image.\n Can be used to add components to the plot.\nRun Code Online (Sandbox Code Playgroud)\n\n笔记:
\n0.5, 0.5偏移xs和ysxpd=NA就是停止“剪辑”;如果没有它,左/右矩形边框的一部分会被剪掉,因此会更薄;不是必需的,但一致数据
\nstats::heatmap(mtx, Colv = NA, scale = "none", add.expr = { browser(); 1; })\nBrowse[4]> par("usr")\n[1] 0.5 5.5 0.5 5.5\nRun Code Online (Sandbox Code Playgroud)\n