I am new in R and I was wondering if I can heatmap my table or matrix which contain TRUE and FALSE ie :
Condition1 Conditions2 . . .
Id1 TRUE FALSE
Id2 FALSE TRUE
.
.
.
My excuse for this naive question and any proposition is welcome to make a heatmap or any tool to visualize my table or matrix by color code and apply clustering or dendrogram based on it.
Thank you in advance
Asked
Active
Viewed 836 times
1

user3037937
- 33
- 3
-
I found a similar question [HERE](http://stackoverflow.com/questions/3280705/how-to-convert-2d-binary-matrix-to-black-white-plot) – Stu Nov 26 '13 at 19:48
2 Answers
2
Assuming you can easily convert TRUE/FALSE to 1,0 numeric
x<-data.frame(y=sample(c(1, 0),10, replace=TRUE), z=sample(c(1, 0),10, replace=TRUE))
heatmap(as.matrix(x))
if needed, to change TRUE/FALSE to 1/0 ,
x[x==TRUE]<-1
x[x==FALSE]<-0

Ananta
- 3,671
- 3
- 22
- 26
-
Actually, you don't need to turn T to 1 or F to 0. It will do that automatically. – Stu Nov 26 '13 at 19:39
-
2Hmm, I get following error `Error in heatmap(as.matrix(x)) : 'x' must be a numeric matrix` without converting, may be for `image` its ok, but not for `heatmap` – Ananta Nov 26 '13 at 19:42
-
1
Use the image() function:
> x=matrix(c(T,F,T,F,F,F,T,T,F,T,T,T,F,F,F,T),ncol=4)
> x
[,1] [,2] [,3] [,4]
[1,] TRUE FALSE FALSE FALSE
[2,] FALSE FALSE TRUE FALSE
[3,] TRUE TRUE TRUE FALSE
[4,] FALSE TRUE TRUE TRUE
> image(t(x),axes=F)
> axis(2,at=seq(0,1,(1/(nrow(x)-1))),labels=nrow(x):1)
> axis(3,at=seq(0,1,(1/(ncol(x)-1))),labels=1:ncol(x))
Give it a shot!

Stu
- 1,543
- 3
- 17
- 31
-
1+1! Shouldn't it, though, be `image(t(x)[,ncol(x):1])`? These squares give me a headache! – alexis_laz Nov 26 '13 at 19:53