Reputation: 101
I am trying to plot a non symmetrical and non squared matrix using heatmap2. But I am getting a message error :
Error in axis(1, at = xv, labels = lv) : no locations are finite
Calls: heatmap.2 -> axis
Execution halted
In fact, my data are in the matrix are equal to 0, 1 or ? (missing values). For example with this matrix :
dat_mat
C1 C2
P17612|KAPCA_HUMAN ? 0
P22612|KAPCG_HUMAN 0 1
P22694|KAPCB_HUMAN 1 0
P31751|AKT2_HUMAN 0 0
The expected result should be a heatmap with red color for "0", green for "1" and nothing (blank) for "?". Here is the R script I am using :
heatmap.2(dat_mat,
Rowv = FALSE,
Colv = FALSE,
dendrogram = "none",
scale = "none",
margins = c(12,24),
key = TRUE,
keysize = 1.0,
col = rainbow(512, start = 1, end = 0.4),
density.info="density",
denscol = "black",
xlab="Compounds",
ylab="Targets",
main="X Activity Profile",
tracecol = "black")
Upvotes: 2
Views: 3268
Reputation: 206232
I'm assuming your data is in the following format:
dat_mat<-matrix(sample(c("?","0","1"), 10*2, replace=T), ncol=2)
colnames(dat_mat)<-c("C1","C2")
rownames(dat_mat)<-letters[1:nrow(dat_mat)]
So you have a character matrix (it's hard to tell from your description). Well, the heatmap is expecting numeric values and it really doesn't like non-standard missing values. So let's remove the "?" and replace them with NA
and then convert to numeric
dat_mat[dat_mat=="?"]<-NA
class(dat_mat)<-"numeric"
That's it. You should now be able to plot this as you expect
heatmap.2(dat_mat,
Rowv=F, Colv=F, dendrogram="none", scale="none",
margins = c(12,24),
key = TRUE,
keysize = 1.0,
col = rainbow(512, start = 1, end = 0.4),
density.info="density",
denscol = "black",
xlab="Compounds",
ylab="Targets",
main="X Activity Profile",
tracecol = "black"
)
Upvotes: 1