有没有办法从geom_tile图中删除空白行?如果我尝试scale = "free"
,它看起来很奇怪。我想保留每个方面的宽度和高度。
这是我的代码:
data.m <- melt(data, id.vars=c("Group","miRNA"))
head(data.m)
# Group miRNA variable value
# 1 Serum hsa-let-7d-5p 1_0h_rep1 0.5356346
# 2 Serum hsa-let-7e-5p 1_0h_rep1 0.5994119
# 3 Serum hsa-let-7g-5p 1_0h_rep1 0.5097298
# 4 Serum hsa-miR-106a-5p 1_0h_rep1 0.3566843
# 5 Serum hsa-miR-1180-3p 1_0h_rep1 0.6019190
# 6 Serum hsa-miR-152-5p 1_0h_rep1 0.1815842
p <- ggplot(data.m, aes(variable, miRNA))
p + geom_tile(aes(fill = value)) + facet_wrap(~Group,ncol=1) +
scale_fill_gradient2(low=muted("blue"), high=muted("red")) +
scale_x_discrete(labels=c("0h_rep2", "0h_rep1", "1h_rep2","1h_rep1","4h_rep2","4h_rep1","9h_rep2","9h_rep1", "15h_rep2", "15h_rep1","18h_rep2","18h_rep1","21h_rep2","21h_rep1")) +
theme_bw(base_size=20) +
theme(axis.text.x=element_text(angle=0, vjust=0.5, hjust=0, size=12), axis.text.y=element_text(size=12), strip.text.y=element_text(angle=0, vjust=0.5, hjust=0.5, size=12),
strip.text.x=element_text(size=12)) +
labs(y="Genes", x="Time (h)", fill="")
答案 0 :(得分:1)
您应该将参数scales="free_y"
添加到facet_wrap()
以删除&#34;清空&#34;线。
+facet_wrap(~Group,ncol=1,scales="free_y")
如果在删除&#34;空&#34;之后需要具有相同宽度的瓷砖然后使用facet_grid()
而不是facet_wrap()
使用参数space="free"
。
+facet_grid(Group~.,scales="free_y",space="free")