Passing parameter to function in add.expr inside heatmap.2

被刻印的时光 ゝ 提交于 2019-12-23 01:41:30

问题


I'm generating clustering heatmap with heatmap.2 function (R gplots package). I'd like to add a vertical line(s) onto the image at variable location(s) using add.expr parameter.

For example,

xx=replicate(10, rnorm(10)) # some random matrix
heatmap.2(xx, trace="none",
          add.expr=abline(v=c(3.5,6.5), lwd=3))

This works great. The problem is it doesn't work if I pass the lines location as a variable:

linePosition = c(3.5,6.5)
heatmap.2(...,
          add.expr=abline(v=linePosition, lwd=3))

It looks like abline function is called from inside the heatmap.2 function and doesn't see the external variables.

Please advice what would be the best approach.

Of course, I don't want to modify any of the functions except my own.


回答1:


This seems to add the two thick lines:

heatmap.2(xx,
       add.expr=eval( abline(v=linePosition, lwd=3))) 


来源:https://stackoverflow.com/questions/18497925/passing-parameter-to-function-in-add-expr-inside-heatmap-2

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!