问题
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