[R] Levelplots with non-continuous x-axis breaks

Pachapep pachapep at gmail.com
Tue Jan 7 04:19:29 CET 2014


Hi all,
I have a matrix which I want to plot in color. I have extensively looked at level plot and heatmap/heatmap.2, but I would like to be able to manage the size of the bins (boxes)  on my X axis. So I thought of simply using the rect() function, but I can’t get around assigning the correct colors to all the values. I have built a RectPlotter() function that takes the start and stop as well as the value assigned to each ‘bin’.
Here is what I have done so far (after countless hours of despair):

RectPlotter <- function(matrixval, ycoord, height, mycolors){
 rect(matrixval[,1], (ycoord-(0.4*height)), matrixval[,2], (ycoord+(0.4*height)), col=mycolors, border = NA)
}

starts <- c(1,5,8,15)
ends <- c(5, 8, 15, 25)
vals1 <- c(2, 15, 7, 13)
vals2 <- c(7, 2, 1, 26)
vals3 <- c(52, 1, 29, 18)
mymatrix <- cbind(starts, ends, vals1, vals2, vals3)
# This gives me an error
mycol<- matrix(nrow=dim(mymatrix)[1], ncol=dim(mymatrix)[2], heat.colors(max(matrix[,3:5]))[matrix[,3:5]])


At the end, I would like to have something like a levelplot, but using the starts and ends as x-axis.
Any help would be highly appreciated. Thanks!
Patrick


More information about the R-help mailing list