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?