You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何调整ggfunc结合ggboxplot中facet.by的多面板为单行布局?

解决方法

你可以通过在ggsummarystats()中添加facet.args参数,指定分面行数为1,强制三个面板在同一行显示。修改后的代码如下:

plot <- df1 %>% filter(PKCYC=="Cycle") %>%
  mutate(DOSE=factor(DOSE)) %>%
  group_by(COUNTRY, TEST) %>%
  ggsummarystats(x = "COUNTRY", y = "value", 
  ggfunc = ggboxplot, add = c("jitter"), 
  color = "COUNTRY", palette = "npg",
  facet.by = c("TEST"), xlab=FALSE, ylab="value",   
  legend="none", 
  free.panels = TRUE,
  ggtheme = theme_bw(),
  facet.args = list(nrow = 1)) # 添加该行指定分面行数

原理说明:ggsummarystats的facet.by参数默认调用facet_wrap(),该函数会自动根据面板数量计算布局(3个面板时默认排成2×2)。通过facet.args传递nrow=1,可以强制所有面板横向排列在同一行,不会出现空面板。

内容的提问来源于stack exchange,提问作者nmfsci

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 05:28:12