我想将我的一个分组箱线图(如下)替换为前后类型,但保持分组。这个是使用ggboxplot()from 制作的ggpubr。我知道也有,ggpaired()但我无法像这样分组。
由于这个问题,我能够创建像这样的分组前后图。我现在想将轴从 4 个标记更改为 2 个(只是“是”和“否”,因为“之前”和“之后”仍在图例中。

这是我的带有虚拟数据的代码:
library(tidyverse)
set.seed(123)
data.frame(ID = rep(LETTERS[1:10], 2),
consent = rep(sample(c("Yes", "No"), 10, replace = T), 2),
height = sample(rnorm(20, 170, sd = 10)),
ind = rep(c("before", "after"), each = 2)
) %>%
ggplot(aes(x = interaction(ind, consent), y = height, color = ind))+
geom_point()+
geom_line(aes(group = interaction(ID, consent)), color = "black")+
scale_x_discrete("response")
Run Code Online (Sandbox Code Playgroud)
甚至可以减少轴上的类别数量吗?或者我可以使用ggpaired(),但不使用构面创建分组图吗?