Reputation: 212
I need to plot a heatmap of a matrix with annotations, so using the heatmap.plus R package I need to use the ColSideColors parameter. The issue here is that it asks for the same dimensions even when those are equal...
> m <- matrix(rnorm(100,1, 20), 10, 10)
> c <- t(as.matrix(rep('gold', 10), ncol=10, nrow=10))
> heatmap.plus(m, ColSideColors=c)
Error in heatmap.plus(m, ColSideColors = c) :
'ColSideColors' dim()[2] must be of length ncol(x)
> dim(c)[2]
[1] 10
> ncol(m)
[1] 10
UPDATE What in the case of the following code?
> m <- matrix(rnorm(100,1, 20), 10, 10)
> c <- t(as.matrix(cbind(rep('gold', 10), rep('blue', 10)), ncol=2, nrow=10))
> heatmap.plus(m, ColSideColors=c)
Error in heatmap.plus(m, ColSideColors = c) :
'ColSideColors' dim()[2] must be of length ncol(x)
> dim(c)[2]
[1] 10
> ncol(m)
[1] 10
in other words, what should I do when I want to build the matrix from vectors...?
Upvotes: 1
Views: 2993
Reputation: 23574
I think your c
is causing the issue. Your c is a matrix by 1 (row) x 10 (columns). But, heatmap.plus
is expecting 10 rows. By following your example, this is what I have done.
m <- matrix(rnorm(100, 1, 20), 10, 10)
c <- matrix("gold", ncol = 10, nrow = 10)
heatmap.plus(m, ColSideColors=c)
I followed the example in the CRAN manual and did the following as well. If necessary, have a look.
m = matrix(rnorm(100,1, 20), 10, 10)
rlab = matrix(c("gold", "green", "blue", "red"), nrow = 10, ncol = 4)
clab = matrix(c("green", "blue"), nrow = 10, ncol =2)
colnames(rlab) = LETTERS[1:dim(rlab)[2]]
colnames(clab) = 1:dim(clab)[2]
heatmap.plus(m,ColSideColors=clab,RowSideColors=rlab)
Upvotes: 2