簡體   English   中英

從圖geom_tile ggplot中刪除空白行

[英]Remove blank lines from plot geom_tile ggplot

有沒有辦法從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="")

您應該將參數scales="free_y"添加到facet_wrap()以刪除“空”行。

 +facet_wrap(~Group,ncol=1,scales="free_y") 

如果在刪除“空”行后需要具有相同的圖塊寬度,請使用facet_grid()而不是帶有參數space="free"facet_wrap()

 +facet_grid(Group~.,scales="free_y",space="free") 

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM