gpt4 book ai didi

r - 如何使用两个因子根据因子水平在 facet_wrap 中换行?

转载 作者:行者123 更新时间:2023-12-05 06:57:52 27 4
gpt4 key购买 nike

如何让每个新行都以新的因子水平开始?目前它基于批处理和样本进行包装,但不会在新的批处理因子级别中断。尝试“facet_grid(~batch~sample)”时,有许多不需要的空面板。

R 的结果和 Photoshop 的预期结果。

enter image description here

编辑以包含较小的可重现数据集

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)

关于r - 如何使用两个因子根据因子水平在 facet_wrap 中换行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64778468/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com