1
votes

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

2
I found a similar question HERE - Stu

2 Answers

2
votes

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
1
votes

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!