R语言 如何创建箱线图和周围相同颜色的点

zengzsys  于 2023-02-06  发布在  其他
关注(0)|答案(1)|浏览(148)

我对这种图表有个问题。
我不知道是否有人可以建议一些教程/网站页面/问题堆栈溢出可以显示如何将有可能创建这种图形,特别是,我感兴趣的是如何获得/显示相同的彩色框周围的斑点。
先谢了

wj8zmpe1

wj8zmpe11#

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)

相关问题