Skip to content
Prev 168248 / 398502 Next

heatmap with levelplot

I played a little bit around and got the following solution which works for
now, though it seems to be too complicated to me.
If anybody else know another solution - please let me know!!!


library(lattice)
my.mat <- matrix(rnorm(800), nrow = 40)

colorFun <- colorRampPalette(c("yellow","red"))

b <- boxplot(my.mat, plot = FALSE)
thr <- c(b$stats[1],b$stats[5])
col.bins <- 100
step <- abs(thr[2] - thr[1])/50

limit <- ifelse(min(my.mat) > thr[1] - step, min(my.mat) - step, min(my.mat))
lp <- rev(seq(thr[1] - step, limit - step, -step))
mp <- seq(thr[1], thr[2], step)
limit <- ifelse(max(my.mat) < thr[2] + step, max(my.mat) + step, max(my.mat))
up <- seq(thr[2] + step, limit + step, step)

my.at <- c(lp,mp,up)

my.col.regions <- c(rep("green", length(lp)), colorFun(length(mp)), rep("blue",
length(up)) )

levelplot(my.mat, at = my.at, col.regions = my.col.regions)






Antje schrieb: