首页 > 解决方案 > 有没有办法从分面环绕图中省略具有 NA 值的变量?

问题描述

# A tibble: 8 × 4
  measurement   log2_fc locus  operon
  <chr>           <dbl> <chr>  <chr> 
1 transcriptome     1   PA3552 arn   
2 transcriptome     1.5 PA3553 arn   
3 proteome         NA   PA3552 arn   
4 proteome          2   PA3553 arn   
5 transcriptome     2.5 PA1179 opr   
6 transcriptome     3   PA1180 opr   
7 proteome         NA   PA1179 opr   
8 proteome         NA   PA1180 opr

plot <- ggplot(data=x,aes(x=locus,y=log2_fc,color=measurement)) +
  geom_jitter()

plot + facet_wrap(~operon, ncol=2)

我正在使用上面的代码创建一个比较通过两种不同测量方法获得的基因 log2_fc 的图。我想通过基因所属的操纵子将绘图分开,但我只想让该操纵子中的基因沿着每个方面的 x 轴绘制。目前它正在创建下面的情节:

tibble x 的 facet_wrap 图

有没有办法只沿着 x 轴绘制每个轨迹值一次,并且仍然让数据由操作子分隔?

标签: rggplot2tibblefacet-wrap

解决方案


您只需要释放 x 轴:

plot + facet_wrap(~operon, ncol=2, scales = "free_x")

如果不指定scales = "free_x",则 ggplot 默认为具有相同限制和中断的相同轴。


推荐阅读