Entering edit mode
Jakub Stanislaw Nowak
▴
70
@jakub-stanislaw-nowak-6656
Last seen 10.2 years ago
Hello bioconductor friends,
I am trying to generate heatmaps for my data and run in following
problems. I would be grateful for some suggestions about heat map
code.
I arranged matrix for the heatmap by myself and I would like to keep
this not changed during heat map plotting. I tried both heatmap.2
(gplot) and geom_tile (ggplot2)
1. So when I used heatmap.2 from (gpot) it keeps my matrix sort but I
have problems making the layout look nice. Below is the code I used.
Can you suggest how to:
a) make rows and columns separated and rows bigger so it can read
easier.
b) is there a way for changing x label for key so it includes min and
max values for colour code.
c) can the density plot be generated above the key
Preparing table for the heatmap.2 from (qplot)
---------------------------------------
```{r}
data.heatmap <- data.sorted.merged[,-c(2:5,8),drop=FALSE]
rownames(data.heatmap)<-data.heatmap$ID
data.heatmap <- data.heatmap[,-1]
data.heatmap.matrix <- data.matrix(data.heatmap)
```
Generating heatmap with heatmap.2
------------------------------
```{r}
if (!require("gplots")) {
install.packages("gplots", dependencies = TRUE)
library(gplots)
}
if (!require("RColorBrewer")) {
install.packages("RColorBrewer", dependencies = TRUE)
library(RColorBrewer)
}
mypalette <- colorRampPalette(c("red", "yellow", "green"))(n = 299)
#subseting default gradient with custom one for better visualisation
colbreaks <- c(seq(-6,-3,length=110), # for red
seq(-3,3,length=90), # for yellow
seq(3.10,length=100)) # for green
heatmap.2(data.heatmap.matrix,
main = "Correlation", # heat map title
notecol="black", # change font color of cell labels to black
density.info="density", # turns density plot inside color legend
trace="none",# turns off trace lines inside the heat map
scale=c("none"),
colsep, rowsep, sepcolor="white", sepwidth=c(1,1), #doesn't really
show any separation
margins =c(1,15), # widens margins around plot doesn't do much
col=mypalette, # use on color palette defined earlier
breaks=colbreaks, # enable color transition at specified limits
Rowv="NA", # only draw a row dendrogram
Colv="NA", # turn off column clustering
key.title=NA, # no title
symkey=FALSE,
)
```
2. I also tried to use geom_tile from (ggplot2) to generate this heat
map. Here layout looks better but I am loosing my organisation of the
matrix. Below is a code I used to make a plot
Can you suggest:
1. how to switch off clustering in ggplot2
Generating heatmap with ggplot2
```{r}
if (!require("reshape2")) {
install.packages("reshape2", dependencies = TRUE)
library(reshape2)
}
if (!require("plyr")) {
install.packages("plyr", dependencies = TRUE)
library(plyr)
}
if (!require("scales")) {
install.packages("scales", dependencies = TRUE)
library(scales)
}
if (!require("ggplot2")) {
install.packages("ggplot2", dependencies = TRUE)
library(ggplot2)
}
data.sorted.merged.test <- data.sorted.merged[,-c(2:5,8)]
data.heatmap2 <- melt(data.sorted.merged.test)
data.heatmap2 <- ddply(data.heatmap2, .(variable), transform,rescale =
rescale(value))
ggplot(data.heatmap2, aes(variable, ID))+ geom_tile(aes(fill=rescale),
colour="white") +
scale_fill_gradient(low="white", high="red", breaks=colbreaks)
```
Also I can attach png files of the heat map if that can help.
Thanks very much for your help,
Jakub
--
The University of Edinburgh is a charitable body, registered in
Scotland, with registration number SC005336.