2016-03-01 78 views
0

我正在設計細胞週期時間序列中調控最強的基因的熱圖。按時間序列排列的時間序列在列中出現峯值時

example <- read.csv("example.csv", header = T) 

example.m <- melt(example) 

(e <- ggplot(example.m, aes(variable, Gene_ID)) + geom_tile(aes(fill = 
value), colour = "white") + scale_fill_gradient(low = "white", high = 
"steelblue")) 

而結果是這樣的,

example heat map

我的價值觀是對數變換,我想知道是否有一種方法可以爲了我的行,以便他們組一起在那裏高峯時間序列(即,在0處具有其最高表達的所有基因被組合在一起,具有在30處最高表達的基因被編組在一起,等等。)
我試圖完成這個像這樣

order <- arrange(example, X0, X30, X60, X90, X120, X150, X180, X210, X240) 

然後經過了用有序數據框繪製熱圖的過程,但沒有改變。
感謝您提供任何幫助或建議。我非常感謝你的時間。

回答

0

你應該能夠加入這一行設定的Y軸的順序example.m$Gene_ID <- factor(example.m$Gene_ID, levels = order$Gene_ID, labels = order$Gene_ID)

下面是完整的代碼示例數據:

example <- data.frame(Gene_ID = paste0("TTHERM_", 1:9), 
         X0 = round(runif(9, min =0, max = 4.4999),0), 
         X30 = round(runif(9, min =0, max = 4.4999),0), 
         X60 = round(runif(9, min =0, max = 4.4999),0), 
         X90 = round(runif(9, min =0, max = 4.4999),0), 
         X120 = round(runif(9, min =0, max = 4.4999),0), 
         X150 = round(runif(9, min =0, max = 4.4999),0), 
         X180 = round(runif(9, min =0, max = 4.4999),0), 
         X210 = round(runif(9, min =0, max = 4.4999),0), 
         X240 = round(runif(9, min =0, max = 4.4999),0)) 

library(dplyr) 
library(reshape2) 
library(ggplot2) 
example.m <- melt(example) 

# This is your original plot 
(e <- ggplot(example.m, aes(variable, Gene_ID)) + geom_tile(aes(fill = 
                    value), colour = "white") + scale_fill_gradient(low = "white", high = 
                                "steelblue")) 
# Your order command gives us the right order 
order <- arrange(example, X0, X30, X60, X90, X120, X150, X180, X210, X240) 

# This changes the order of the Y axis based on the sort order 
example.m$Gene_ID <- factor(example.m$Gene_ID, levels = order$Gene_ID, labels = order$Gene_ID) 

# This is the new plot 
(e <- ggplot(example.m, aes(variable, Gene_ID)) + geom_tile(aes(fill = 
                    value), colour = "white") + scale_fill_gradient(low = "white", high = 
                                "steelblue")) 

原創情節:

enter image description here

新地塊:

enter image description here

這是你想要的嗎?

+0

關閉,我希望能在他們偷看的地方點餐。如果表達式在0時最高,則它將與其他在0處具有最高表達式的其他人組合在一起,依此類推。我不相信我的安排功能能夠完成這個任何建議? – Lindsley

+0

你把所有那些最高的零組合在一起,所以我不太明白你想要什麼。你不能將最高爲零的那些分組在一起,並且同時將最高爲30的那些分組在一起。 – Mist