Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to draw a straight line in heatmap plot

Tags:

plot

r

I am making a heatmap for some data and want to add a straight line between each set of samples. It seems like abline doesn't work well on heatmap.

Any idea what function I can use for this purpose?

like image 761
user2571475 Avatar asked Sep 15 '25 15:09

user2571475


1 Answers

You have to use the add.expr argument. This example found here might be usefull:

x  <- as.matrix(mtcars)
rc <- rainbow(nrow(x), start=0, end=.3)
cc <- rainbow(ncol(x), start=0, end=.3)
hv <- heatmap(x, col = cm.colors(256), scale="column",
               RowSideColors = rc, ColSideColors = cc, margin=c(5,10),
               xlab = "specification variables", ylab= "Car Models",
               main = "heatmap(<Mtcars data>, ..., scale = \"column\")",
               # IMPORTANT BIT HERE
               add.expr = abline(h=5, v=2))
like image 85
QuantIbex Avatar answered Sep 17 '25 05:09

QuantIbex