When I decided to switch from SAS to [tag]R project[/tag], it was because somebody told me that multivariate analysis and plots like [tag]heatmap[/tag] are much easier to do in R. I guess somebody should have told me what I learned much later, that R has a steep learning curve. I guess my is already flattening a bit, but I just recently spend two weeks figuring out how to draw heatmap. Maybe because all the needed information were not available in one spot, and -’x’ must contain finite values only- and -’x’ must be a numeric matrix – in Google search results in brilliant responses of those who master R in this style – if your R tells you the data set is wrong, it is, so look for idiotic entries. Aha. Or read your manual, this one is even more irritating.
Anyway, let me write how to avoid some traps and looking for help from professionals, who usually make you just feel more stupid then you are, unfortunately
.
You may want to do scaling using scale function, as described with PCA, or not. Up to you. The first trick then is to get rid of your sample/group names, or whatever text you have in first column:
data.names <- data[,1]
data.set <- data[,-1]
Next, make sure your data is in matrix rather than data frame:
data.map <- as.matrix(data.set)
The heatmap, opposite to PCA, takes missing data without any problem, just leaves you with blank spots. You just have to be careful, if you color scheme contains white color as well.
Now all you do is:
heatmap(data.map)
Well, maybe you don’t like colors too much. You can personalize your heatmap a bit:
heatmap(data.map, col=topo.colors, labRow=data.names, xlab=’variables’, ylab=’samples’)
However, the colors schemes are limited to:
cm.colors
topo.colors
terrain.colors
rainbow
heat.colors
Also, I am sure you could figure out how to add color legend, but what for, if the appropriate function is there for you. Just download gplots library:
heatmap.2(data.map, col=greenred(256), density.info=’none’, trace=’none’, cexRow=0.5, labRow=data.names)
You have some additional color schemes, and you can read more about it here.