我正在设计细胞周期时间序列中受监管最严格的基因的热图。
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"))
结果看起来像这样,
我的值是对数转换的,我想知道是否有一种方法可以对我的行进行排序,以便它们按时间序列的峰值组合在一起(即所有在0处具有最高表达的基因组合在一起,在30处具有最高表达的基因被组合在一起,依此类推。)
我试图像这样完成这个
order <- arrange(example, X0, X30, X60, X90, X120, X150, X180, X210, X240)
然后经历了使用有序数据框绘制热图的过程,但它没有改变 感谢您提供的任何帮助或建议。我非常感谢你的时间。
答案 0 :(得分: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"))
原图:
新剧情:
这是你想要的吗?