从plot geom_tile ggplot中删除空行 [英] Remove blank lines from plot geom_tile ggplot

查看:116
本文介绍了从plot geom_tile ggplot中删除空行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法从geom_tile图中删除空行?如果我尝试 scale =free,它看起来很奇怪。我想保留每个方面的宽度和高度。
这是我的代码:

  data.m<  -  melt(data,id.vars = c( (miRNA))
head(data.m)
#Group miRNA变量值
#1血清hsa-let-7d-5p 1_0h_rep1 0.5356346
#2血清hsa-let-7e-5p 1_0h_rep1 0.5994119
#3血清hsa-let-7g-5p 1_0h_rep1 0.5097298
#4血清hsa-miR-106a-5p 1_0h_rep1 0.3566843
#5血清hsa- miR-1180-3p 1_0h_rep1 0.6019190
#6血清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(低=静音(蓝色),高=静音(红色)) +
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 = e (大小= 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 =)


解决方案 c $ c $>删除空行。

  + facet_wrap(〜Group,ncol = 1,scales =free_y )

如果您在删除空行后需要具有相同宽度的磁贴,请使用 facet_grid()而不是 facet_wrap()带参数 space =free
$ p $ + facet_grid(Group〜。,scales =free_y,space =free)


Is there a way to remove the blank lines from a geom_tile plot? If I try scale = "free" it looks weird. I want to preserve the width and height of each facet. Here is my code:

 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="")

解决方案

You should add argument scales="free_y" to facet_wrap() to remove "empty" lines.

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

If you need to have the same width of tiles after removing the "empty" lines then use facet_grid() instead of facet_wrap() with argument space="free".

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

这篇关于从plot geom_tile ggplot中删除空行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆