Reputation: 266
I am trying to make a heatmap. I have a csv file that has a list of samples, and data at numerous timepoints. So it looks like this
Sample 1h 2h 3h 4h 5h 6h 7h
Test1
Test2
except much bigger and obviously filled with data. My goal is to make a heatmap, so that I can see visually if there is a higher measurement at earlier timepoints. So I dont really care what the values are of each sample in relation to each other. I care which timepoints had the largest values for each sample.
I can make a heatmap but Im fairly certain when it scales, it is scaling each column. But for what I want to do I believe it should be scaling each row. How do I do this? Thank you
library(ggplot2)
library(reshape)
library(scales)
library(plyr)
library(reshape2)
data <- read.table('HB-1ng-1.5000.matrix', header = T, sep = '\t')
data.m <- melt(data)
data.m <- ddply(data.m, .(variable), transform, rescale = scale(value))
p <- ggplot(data.m, aes(variable, Sample)) + geom_tile(aes(fill = rescale), colour = "white") + scale_fill_gradient(low = "white", high = "steelblue")
Upvotes: 2
Views: 3175
Reputation: 1716
How about rescaling before melting:
dataRowNorm <- t(apply(data, 1, function(x) x/sum(x)))
Then melt, rename columns possibly and pass to ggplot.
Upvotes: 3