Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Binary R heatmap still displays gradient

Tags:

r

heatmap

I'm trying to plot a heatmap for a matrix of binary data (11 x ~1500) in R.

heatmap(y, col = hmcols);

the matrix 'y' looks like this

[,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10] [,11] [,12] [,13]
[1,]    0    0    0    0    1    1    1    1    1     1     1     1     1
[2,]    0    0    1    0    0    1    0    0    0     0     0     0     1
[3,]    0    0    0    0    0    1    1    1    1     0     0     1     1 ...etc...

I'm using the default distance and clustering functions, but for some reason my heatmap displays a gradient of color. I've tried to use the binary distance function as well, although a similar gradied occurs. Is this a lack of similarity in samples due to the distance between each sample? Here is an image of the heatmap:

https://www.dropbox.com/s/jz1r41lhnrkisvz/Rplots.pdf

I feel like this is due to my lack of understanding of exactly how the default distance and clustering functions reorder data. How can I interpret these results?

like image 255
alternated direction Avatar asked Sep 13 '13 23:09

alternated direction


People also ask

How do you split a heatmap?

You can split the heatmap by the subgroup variable (see Section 2.7), or you can use cluster_within_group() clustering function to generate a special dendrogram. In above example, columns in a same group are still clustered, but the dendrogram is degenerated as a flat line.

How do I change the color of my heatmap in R?

To add colors to such heatmap in ranges, use scale_fill_manual() with a vector of the colors for each range. Example: R.

What does a heatmap show in R?

A heatmap is a graphical representation of data where the individual values contained in a matrix are represented as colors. This page displays many examples built with R, both static and interactive. The heatmap() function is natively provided in R.


1 Answers

As @Joran point out, the scale argument is the one to go with:

(Note: I reduced dimensionality and generated random data since you did not provide your full set)

The colors are chosen by col, if you want simple black and white you can do col = c("black", "white"), but you can also make things more interesting:

x <- matrix(sample(c(0, 1), 15*15, replace = TRUE), nrow = 15)
heatmap(x, scale = "none", Rowv = NA, Colv = NA, col = cm.colors(2), main = "HeatMap Example") 

enter image description here

like image 56
mlegge Avatar answered Oct 17 '22 04:10

mlegge