0

I want to plot a data with heatmap. But before plotting I would like to scale them using my own functions.

This is the full code:

library("gplots")
mydata <- mtcars


# Functions
hclustfunc <- function(x) hclust(x, method="complete")
distfunc <- function(x) dist(x,method="euclidean")


# My own scaling function
customize.zscore <- function(x,cust.mean=1,cust.sd=1) {
    themean <- cust.mean
    thesd <- cust.sd
    z <- (x - themean) / (thesd)
    return (z)
}


mean.all <- mean(as.vector(t(mtcars)));
sd.all<- sd(as.vector(t(mtcars)));


# Scale the data
dat.1 <- as.data.frame(t(apply(mtcars,1,function(x) customize.zscore(x,cust.mean=mean.all,cust.sd=sd.all))))
head(dat.1)

# Plot the scaled data
heatmap.2(as.matrix(dat.1),dendrogram="row",trace="none", margin=c(8,9), hclust=hclustfunc,distfun=distfunc);

As you can see in the output of head(dat.1) the data is scaled correctly ranging from
-0.4703658 to 5.134808.

But why the plot below doesn't reflect that? As you can see in the ColorKey the value range from 0 to 5?

enter image description here

pdubois
  • 7,640
  • 21
  • 70
  • 99
  • 1
    Could you elaborate more on what would you like to observe? I think the graph above reflects your scaled data. The frequency histogram in the colour key shows that the majority of the values are below 0. If you are interested to contrast the values below and above 0, you may try different colouring `col=bluered(256)`, while `symbreak=TRUE` will adjust the colour scale, so it breaks around 0. – TWL Dec 10 '13 at 13:54
  • 1
    Also, you may find this [post](http://stackoverflow.com/questions/17924828/differences-in-heatmap-clustering-defaults-in-r-heatplot-versus-heatmap-2/20370058#20370058) interesting. It will tell you how you can assign the limit values to your scaled data. – TWL Dec 10 '13 at 13:58

0 Answers0