0

I am tryin to add p-values of 3 factors T-test on ggplot. But it keeps warning me this kind of error calls 'Error in FUN(X[[i]], ...) : object 'estimate' not found'. My coding is following:

Fisrt, I did a t-test

mixt.test_others<-studymix_fit %>%
  group_by(reciprocity,stimu)%>%
  t_test(Study_rate ~ estimate)%>%
  adjust_pvalue()%>%
  add_significance()

  mixt.test_others1 <- mixt.test_others %>%
  add_xy_position(x = "estimate", fun = "mean_sd", dodge = 0.8)

Then I add it to ggplot

ggplot(studymix_fit,aes(x=reciprocity, y=Study_rate,color = estimate, 
                        fill = estimate))+
  facet_grid(. ~ stimu)+
  geom_violin(alpha = 0.1, adjust = 1.5)+
  geom_boxplot(width = 0.1,alpha = 0.2,
               position = position_dodge(width = 0.9))+
  geom_dotplot(binaxis = "y", stackdir = 'center',
               dotsize = 0.5, alpha = 0.5,
               position = position_dodge(width = 0.9) )+
  stat_summary(fun.data="mean_sdl", fun.args = list(mult=1),
               geom="pointrange", 
               color = "red", alpha = 1,width = 0.15,
               position = position_dodge(width = 0.9))+
  stat_compare_means(method = 'anova', label.y = 1.4)+
  add_pvalue(mixt.test_others1,
             label = "p = {p.adj.signif}",
             tip.length = 0.01,
             step.increase = 0.05,
             y.position = 1.05)+
  theme_classic()+
  scale_fill_brewer(type = 'div', palette = 'Accent', direction = 1)+
  scale_color_brewer(type = 'div', palette = 'Accent', direction = 1)+
  labs(x="Reciprocity",y="Select Rate of Positive Reciprocity")

Here are part of my dataset:

structure(list(ID = c(102, 102, 102, 102, 103), 
condition = c("A", "C", "B", "D", "A"), 
Study_rate = c(1, 0, 1, 0, 0.666666667), 
reciprocity = c("PS", "NS", "PS", "NS", "PS"), 
estimate = c("PO", "PO", "NO", "NO", "PO"), 
stimu = c("subject", "subject", "subject", "subject", "subject"))

Actually, I checked my original data set, it seems no problem. I wanna know if I did the 3 factor t-test well? Is there any other problem I made? Please help me figure it out, thanks very much If anyone has similar problems, we can disccus and figure them out~ Thanks

YUE ZHAO
  • 1
  • 2
  • 1
    It would be easier to help you if you provide [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data or some fake data. Please do not post an image of code/data/errors [for these reasons](https://meta.stackoverflow.com/questions/285551/why-not-upload-images-of-code-errors-when-asking-a-question/285557#285557). Instead add the snippet of your data directly using e.g. `dput()`. For more on that see the first link. – stefan Sep 15 '22 at 06:13

0 Answers0