Patrick,
You were pretty close.
To fix the code you have, just change "matrix" to "mymatrix" in two places,
and either specify the argument data= or place the heat.colors bit first in
the matrix function.
Or ... you could use the array() function instead, to shorten up the code a
little.
mycol <- array(heat.colors(max(mymatrix[, 3:5]))[mymatrix[, 3:5]],
dim=dim(mymatrix))
Jean
On Mon, Jan 6, 2014 at 9:19 PM, Pachapep wrote:
> 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
> ______________________________________________
> R-help@r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
> http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>
[[alternative HTML version deleted]]