将统计测试与rstatix和每个类别的颜色填充相结合

将统计测试与rstatix和每个类别的颜色填充相结合,r,ggplot2,t-test,violin-plot,R,Ggplot2,T Test,Violin Plot,我使用此代码使用ggplot2进行小提琴绘图: Cells1 %>% ggplot(aes(x=IR_time, y=AreaShape_Area, fill=IR_time)) + geom_violin(col=NA) + guides(fill=FALSE) + stat_summary(fun.data=data_summary, col = "black") + theme_gray() + ggtitle("Cell a

我使用此代码使用ggplot2进行小提琴绘图:

Cells1 %>%
  ggplot(aes(x=IR_time, y=AreaShape_Area, fill=IR_time)) +
  geom_violin(col=NA) +
  guides(fill=FALSE) + 
  stat_summary(fun.data=data_summary, col = "black") +
  theme_gray() + 
  ggtitle("Cell area after irradiation (3Gy)") +
  ylab("\nArea (pixels)") + 
  xlab("\nDays after exposure to 3Gy\n") +
  scale_fill_manual(values=wes_palette(n=5, name="Moonrise3")) +
  theme(
    plot.title = element_text(size=16),
    axis.title = element_text(size=12, face="bold"),
    axis.text = element_text(size=12))
生成此图的:

现在我想执行一个统计检验(这里是一个成对的t检验),并将结果添加到绘图上。我使用rstatix软件包。 下面是新代码:

stat.test <- Cells1 %>%  pairwise_t_test(AreaShape_Area ~ IR_time, pool.sd=FALSE, p.adjust.method="bonferroni", ref.group="0") %>% 
  add_y_position()

    Cells1 %>%
      ggplot(aes(x=IR_time, y=AreaShape_Area, fill=IR_time)) +
      geom_violin(col=NA) +
      guides(fill=FALSE) + 
      stat_summary(fun.data=data_summary, col = "black") +
      theme_gray() + 
      ggtitle("Cell area after irradiation (3Gy)") +
      ylab("\nArea (pixels)") + 
      xlab("\nDays after exposure to 3Gy\n") +
      scale_fill_manual(values=wes_palette(n=5, name="Moonrise3")) +
      theme(
        plot.title = element_text(size=16),
        axis.title = element_text(size=12, face="bold"),
        axis.text = element_text(size=12)) +
      stat_pvalue_manual(stat.test) 
stat.test%成对测试(AreaShape\u Area~IR\u time,pool.sd=FALSE,p.adjust.method=“bonferroni”,ref.group=“0”)%>%
添加_y_位置()
单元格1%>%
ggplot(aes(x=红外时间,y=面积形状面积,填充=红外时间))+
geom_小提琴(col=NA)+
导向装置(填充=假)+
统计汇总(fun.data=数据汇总,col=“黑色”)+
theme_gray()+
ggtitle(“辐照后的细胞面积(3Gy)”)+
ylab(“\n区域(像素)”)+
xlab(“暴露于3Gy后的第二天”)+
比例填充手册(值=wes调色板(n=5,name=“Moonrise3”))+
主题(
plot.title=元素\文本(大小=16),
axis.title=元素\文本(大小=12,面=“粗体”),
axis.text=元素\文本(大小=12))+
统计值手册(统计测试)
但它导致了这个错误:

错误:长度必须为1或与数据(4):填充相同

显然,这来自aes()中的fill=IR_time参数。 如果我用fill=“blue”替换它,它会工作,我没有错误消息。 但是我想要两种颜色,取决于红外时间和绘图的统计数据


您知道如何修复它吗?

我创建了一个大致相似的数据集,名称相同:

set.seed(69)
细胞1