如何创建箱线图和它们周围的相同颜色的点

How to create boxplot graph and same coloured spots around them

我对这种图表有疑问。

我不知道是否有人可以在 Stack Overflow 上提出一些 tutorials/websites pages/question 可以展示如何创建这种图表的建议,具体来说,我很感兴趣关于如何 obtain/show 相同颜色框周围的斑点。

提前致谢

根据 OP 请求更新:

代码:

library(ggpubr)


# create fake data mtcars1
mtcars1 <- mtcars %>% 
  add_row(mtcars[1,]) %>% 
  mutate(group = rep(c("A", "B", "C"), 11))

compare_means(disp ~ cyl, data = mtcars1,  method = "t.test")
my_comparisons <- list( c("4", "6"), c("6", "8"), c("4", "8") )

ggboxplot(mtcars1, x = "cyl", y = "disp", fill = "cyl", add = "jitter") +
  scale_fill_manual(values=c("#0433ff", "#fe403f", "#66cd00")) +
  stat_compare_means(comparisons = my_comparisons)+
  stat_compare_means(label.y = 700) +
  facet_grid(.~group, switch = "x")+
  xlab(NULL) +
  theme(strip.background = element_blank(),
        strip.placement = "outside")

这是一个使用 ggpubr 包和 mtcars 数据集的示例:

library(ggpubr)

compare_means(disp ~ cyl, data = mtcars,  method = "t.test")
my_comparisons <- list( c("4", "6"), c("6", "8"), c("4", "8") )

ggboxplot(mtcars, x = "cyl", y = "disp", color = "cyl", add = "jitter") +
  stat_compare_means(comparisons = my_comparisons)+
  stat_compare_means(label.y = 700)