我正在尝试制作一个昼夜节律基因表达数据的热图,并在其上方显示所测量的行为。
我希望它看起来像这样:

请注意,2个红点应分别位于CT13和CT37之上...
这是我尝试使用的代码,但它产生了两个独立的图形:
library(pheatmap)
library(RColorBrewer)
library(ggplot2)
# prepare data for Heat map:
my_heatmap <- read.csv("circ_genes.csv", header = TRUE)
mymat <- my_heatmap[,c(2:13)]
rownames(mymat) <- paste("Gene", my_heatmap[,1], sep="_")
mydf <- data.frame(row.names = paste("Gene", my_heatmap[,1], sep="_"),
category = my_heatmap[,14])
my_palette <- colorRampPalette(c("blue", "white", "red"))(n = 1000)
# prepare data for line graph
behavior_LD <- read.csv("behavior.csv", header = TRUE)
CT <- behavior_LD$CT
CT <- as.character(CT)
behavior_LD$CT <- factor(behavior_LD$CT, levels = CT )
mycolours <- c("H1" = "red", "H0" = "black")
behavePlot <- ggplot(data=behavior_LD, aes(x=CT, y=Average, group=1)) +
geom_line()+
geom_point(aes(colour = factor(highlight)), size = 3) +
geom_errorbar(aes(ymin=Average-SE, ymax=Average+SE), width=.1)+
scale_color_manual(values = mycolours) + theme(legend.position="none") +
theme(axis.title.x=element_blank(),
axis.text.x=element_blank(),
axis.ticks.x=element_blank()) +
theme(plot.margin=unit(c(5,2,5,2),"cm"))
# plot 2 graphs
par(mfrow=c(2,1))
behavePlot
pheatmap(mymat, color = my_palette, legend_labels = "Clusters", cluster_cols
= F, cluster_rows = F, annotation_row = mydf, gaps_row = c(43, 60, 88, 124),
annotation_names_row = FALSE, show_rownames = FALSE )我使用的文件可以在这里找到:https://www.dropbox.com/sh/n3mplr0fdz7oh6f/AACU_CdVjT6OmJLzrKmAtxj2a?dl=0
谢谢你的帮助!
发布于 2018-01-24 21:14:29
首先,删除
theme(plot.margin=unit(c(5,2,5,2), "cm")) 从您的顶部折线图代码。
然后,只需在每个gtable中填充一些缺少的列,并添加一些填充:
library(gtable)
library(grid.arrange)
top <- ggplotGrob(behavePlot)
bot <- phm$gtable
bot1 <- gtable_add_cols(bot, unit.c(top$widths[[1]], top$widths[[2]], top$widths[[3]]), 0)
top1 <- gtable_add_cols(top, bot$widths[[6]])
grid.newpage()
grid.draw(
gtable_add_padding(
arrangeGrob(top1, bot1, ncol=1, nrow=2, heights=c(0.2, 0.8)),
unit(c(0, 2, 0, 2), "lines")
)
)

注意:这是一个实现了你想要的结果的小技巧,但是非常脆弱。希望Claus能发现这个问题,并为你提供一个更优雅的解决方案。
https://stackoverflow.com/questions/48421515
复制相似问题