User:Timothee Flutre/Notebook/Postdoc/2011/11/07: Difference between revisions

From OpenWetWare
Jump to navigationJump to search
(Autocreate 2011/11/07 Entry for User:Timothee_Flutre/Notebook/Postdoc)
 
(→‎Entry title: myheatmap)
Line 7: Line 7:
<!-- ##### DO NOT edit above this line unless you know what you are doing. ##### -->
<!-- ##### DO NOT edit above this line unless you know what you are doing. ##### -->
==Entry title==
==Entry title==
* Insert content here...
* customize the built-in heatmap in R (inspired from [http://stackoverflow.com/questions/5687891/r-how-do-i-display-clustered-matrix-heatmap-similar-color-patterns-are-grouped/5694349 this]):
 
S <- 3  # nb of subgroups
V <- 7  # nb of observations
z <- matrix(c(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0), nrow=V, ncol=S, byrow=TRUE)
myheatmap <- function(z, out.file="") {
  def.par <- par(no.readonly=TRUE)
  par(mar=c(4,5,3,2), font=2, font.axis=2, font.lab=2, cex=1.5, lwd=2)
  if (out.file != "")
    pdf(out.file)
  layout(mat=cbind(1, 2), width=c(7,1))  # plot +  legend
  mycol <- rev(heat.colors(4))
  image(x=1:NCOL(z), y=1:NROW(z), z=t(z),
        xlim=0.5+c(0,NCOL(z)), ylim=0.5+c(0,NROW(z)),
        xlab="", ylab="Observations sorted by cluster", main="Custom heatmap",
        axes=FALSE, col=mycol)
  axis(1, 1:NCOL(z), labels=paste("subgroup", 1:NCOL(z)), tick=0)
  par(mar=c(0,0,0,0))
  plot.new()
  legend("center", legend=sprintf("%.2f", seq(from=min(z), to=max(z), length.out=5)[-1]),
          fill=mycol, border=mycol, bty="n")
  if (out.file != "")
    dev.off()
  par(def.par)
  }
myheatmap(mydata.sort)





Revision as of 16:51, 7 November 2011

Project name <html><img src="/images/9/94/Report.png" border="0" /></html> Main project page
<html><img src="/images/c/c3/Resultset_previous.png" border="0" /></html>Previous entry<html>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</html>Next entry<html><img src="/images/5/5c/Resultset_next.png" border="0" /></html>

Entry title

  • customize the built-in heatmap in R (inspired from this):
S <- 3  # nb of subgroups
V <- 7  # nb of observations
z <- matrix(c(0,0,0,0,0,0,0,0,0,1,1,1,1,1,1,0,1,1,1,0,0), nrow=V, ncol=S, byrow=TRUE)

myheatmap <- function(z, out.file="") {
  def.par <- par(no.readonly=TRUE)
  par(mar=c(4,5,3,2), font=2, font.axis=2, font.lab=2, cex=1.5, lwd=2)
  if (out.file != "")
    pdf(out.file)
  layout(mat=cbind(1, 2), width=c(7,1))  # plot +  legend
  mycol <- rev(heat.colors(4))
  image(x=1:NCOL(z), y=1:NROW(z), z=t(z),
        xlim=0.5+c(0,NCOL(z)), ylim=0.5+c(0,NROW(z)),
        xlab="", ylab="Observations sorted by cluster", main="Custom heatmap",
        axes=FALSE, col=mycol)
  axis(1, 1:NCOL(z), labels=paste("subgroup", 1:NCOL(z)), tick=0)
  par(mar=c(0,0,0,0))
  plot.new()
  legend("center", legend=sprintf("%.2f", seq(from=min(z), to=max(z), length.out=5)[-1]),
         fill=mycol, border=mycol, bty="n")
  if (out.file != "")
    dev.off()
  par(def.par)
 }

myheatmap(mydata.sort)