R ggplot2箱线图镶嵌面包裹

R ggplot2箱线图镶嵌面包裹,r,ggplot2,boxplot,facet-wrap,R,Ggplot2,Boxplot,Facet Wrap,我试图在R中使用ggplot2在不同的面板或面中构建具有不同参数集的箱线图。在我的输入数据表中,有一列“process”,其中包含参数分组。但是,当我使用facet_wrap绘图时,每个facet的所有参数都会显示出来,即使大多数没有数据,即使我使用drop=T 下面是我的代码,任何建议都会很有帮助 ggplot(stRep, aes(x=Parameter, y=value, fill=Disease), facets=process) + geom_boxplot(outlier.sh

我试图在R中使用ggplot2在不同的面板或面中构建具有不同参数集的箱线图。在我的输入数据表中,有一列“process”,其中包含参数分组。但是,当我使用facet_wrap绘图时,每个facet的所有参数都会显示出来,即使大多数没有数据,即使我使用drop=T

下面是我的代码,任何建议都会很有帮助

ggplot(stRep, aes(x=Parameter, y=value, fill=Disease), facets=process) + 
  geom_boxplot(outlier.shape=NA) + 
  ylab("Posterior distribution") + 
  xlab("Parameter") + theme_bw() + 
  scale_fill_grey() + coord_flip() +  
  ylim(-6, 10) + 
  facet_wrap( ~ process, drop=T,  ncol=1)
附件是数据的一个子集:

> test[c(1:5, 39995:40005),]
            value           Parameter Disease              process
5001  -4.52611948 initial probability    tree   General parameters
5002   6.73178928      pers.intercept    tree          Persistence
5003   6.00318901      pers.intercept    tree          Persistence
5004  -4.05923658   pers. nei. effect    tree          Persistence
5005   0.05733596   pers. nei. effect    tree          Persistence
39995 -0.10238927    col. tick effect    corn Initial colonization
39996 -0.12752092    col. tick effect    corn Initial colonization
39997 -0.17067746    col. tick effect    corn Initial colonization
39998 -0.06580708    col. tick effect    corn Initial colonization
39999 -0.13382417    col. tick effect    corn Initial colonization
40000 -0.12990795    col. tick effect    corn Initial colonization
40001  0.22196724    col. Lyme effect    corn Initial colonization
40002  0.24598469    col. Lyme effect    corn Initial colonization
40003  0.26436187    col. Lyme effect    corn Initial colonization
40004  0.23429840    col. Lyme effect    corn Initial colonization
40005  0.22931861    col. Lyme effect    corn Initial colonization

如果发布一些数据,测试各种选项会更容易

但是,听起来您应该在绘图之前对数据进行子集划分:

stRep_no0s <- subset(stRep, value>0)
使用
+facet\u wrap(~process,scales=“free\u x”,ncol=1)
是否可以满足您的需要
drop=T
意味着没有为没有数据的
过程
的级别绘制面。是的,scales=“free_x”选项确实是我想要使用的,但不能与ggplot2中的coord_flip()选项一起使用。这有什么办法吗?
ggplot(stRep_no0s, aes(x=Parameter, y=value, fill=Disease), facets=process) + 
  geom_boxplot(outlier.shape=NA) + 
  ylab("Posterior distribution") + 
  xlab("Parameter") + theme_bw() + 
  scale_fill_grey() + coord_flip() +  
  ylim(-6, 10) + 
  facet_wrap( ~ process, scales="free_x",  ncol=1)