如何创建箱线图及其周围相同颜色的点[关闭]

问题描述 投票:0回答:1

我对这种图表有疑问。

我对如何获取/显示同一颜色框周围的斑点感兴趣。

提前致谢

r ggplot2 boxplot
1个回答
3
投票

根据 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) 

© www.soinside.com 2019 - 2024. All rights reserved.