r - 如何根据使用两个因素的因素级别在 facet_wrap 中打破新行?
问题描述
如何使每个新行都以新的因子水平开始?目前它基于批次和样本进行包装,但不会在批次的新因子水平上中断。尝试 'facet_grid(~batch~sample)' 时,有许多不需要的空面板。
R 的结果和 Photoshop 的所需结果。
编辑以包含较小的可重现数据集
df <- data.frame("sample" = c("A1","A2","A3","A4","A5","A6","A7","A8","A9","A10","A11"),
"length_um" = c(1.8,1.9,0.52,0.75,0.14,0.95,0.84,0.46,0.25,0.13,0.31),
"breadth_um" = c(1.44,1.52,0.41,0.60,0.12,0.76,0.68,0.37,0.20,0.11,0.25),
"batch" = c("batch01","batch01","batch01","batch01","batch02","batch02","batch02","batch02","batch02","batch03","batch03"))
df <- df %>%
mutate_if(sapply(df, is.character), as.factor)
ggplot(df, aes(x=length_um,y=breadth_um)) +
geom_point()+
facet_wrap(~batch~sample)
解决方案
尝试替换facet_wrap(~batch~sample)
为facet_grid(~batch~sample)
.
推荐阅读
- google-cloud-run - 使用 Google Cloud Run 的 Google Cloud Endpoints 错误:无法处理请求
- python - 如何构造 css_selector 以使用 Selenium 和 Python
- php - 我正在尝试将用户浏览器详细信息存储在数据库中-
- kendo-ui - KendoUI 网格自动将列调整到最小/最大宽度
- java - 如何使用 springdoc-openapi-webflux-ui 显示应用程序 API 文档?
- julia - Julia Flux 错误:SGD 优化器未定义
- maven - 包导入 org.apache.storm.hbase.* 不存在
- reactjs - 用户选择的日期不显示在输入框中
- android - 将小部件直接放在 Row 小部件下方
- c# - 如何在 Devexpress XtraOpenFileDialog 中禁用右键单击?