Hi Jakub,

On Fri, Aug 8, 2014 at 7:06 AM, Jakub Stanislaw Nowak <jakub.nowak@ed.ac.uk>
wrote:

> 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.
>

Put it in a pdf that is longer than it is tall:

pdf("heatmap.pdf', 10,50)
heatmap.2(<args>)
dev.off()


> b) is there a way for changing  x label for key so it includes min and max
> values for colour code.
>

Well you can change the x label, but I don't think that is what you are
talking about. Instead I believe you are asking about the x tick labels. In
which case, from ?heatmap.2:

key.xtickfun: function computing tick location and labels for the xaxis
          of the color key. Returns a named list containing parameters
          that can be passed to ‘axis’. See examples.

And as advertised, there is an example of how you can change things.

c) can the density plot be generated above the key
>

Of course! Anything _can_ be done. But that doesn't mean it will be easy to
do. Right above the example that shows how to change the key axis labels is
an example of how you can use the 'extrafun' argument to replace the key
entirely with a scatterplot. You could write a function that generates the
key with a density plot right above it, and then pass that in via the
extrafun argument.

Best,

Jim



>
> 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.
>
> _______________________________________________
> Bioconductor mailing list
> Bioconductor@r-project.org
> https://stat.ethz.ch/mailman/listinfo/bioconductor
> Search the archives:
> http://news.gmane.org/gmane.science.biology.informatics.conductor
>



-- 
James W. MacDonald, M.S.
Biostatistician
University of Washington
Environmental and Occupational Health Sciences
4225 Roosevelt Way NE, # 100
Seattle WA 98105-6099

	[[alternative HTML version deleted]]

