ggpubr icon indicating copy to clipboard operation
ggpubr copied to clipboard

Error: Aesthetics must be either length 1 or the same as the data (81): group, step.increase, bracket.nudge.y and bracket.shorten

Open drstormR opened this issue 3 years ago • 4 comments

When using the stat_pvalue_manual(data= stat.test, label = "p.adj.signif") i get the above error message.

library(ggplot2) library(tidyverse) library(rstatix) library(ggallin) library(ggpubr)

stat.test <- test %>% mutate(var2 = variable) %>% group_by(var2) %>% t_test(diff ~ 2_sided_value) %>% adjust_pvalue(method ="BH") %>% add_significance() %>% add_xy_position(x='prog', fun='max') stat.test

test %>% ggplot(aes(x = prog, y = diff)) + geom_boxplot(aes(fill=prog),width=0.6) + facet_grid( ~ variable)+ scale_y_continuous(trans = pseudolog10_trans) labs( title = "Difference", subtitle = "Measurement", caption = "Cancerstudy", x = "response - non response", y = "Difference ", ) + theme( plot.title = element_text(color = "#0099f8", size = 16, face = "bold", hjust = 0.5), plot.subtitle = element_text(face = "bold.italic", hjust = 0.5), plot.caption = element_text(face = "italic") ) + stat_pvalue_manual(data= stat.r848, label = "p.adj.signif")

Code runs just fine without the last "stat_pvalue_manual" line, but gives an aesthetic problem. Does not help with inherit.aes = FALSE.

Any idea how to fix thix? Been looking all over and nothing seems to work this far.

Thanks Dag.

drstormR avatar Feb 04 '22 07:02 drstormR

I have the same issue, and I'm following the tutorial on the reference page. @drstormR Were you successful in finding a solution?

FarzanT avatar Mar 05 '22 20:03 FarzanT

Hi, yes I did find a simple solution. It seems that if you avoid using column name ‘variable‘ in your long data frame, it works fine.

Let me know if it works for you as well.

Den 5. mar. 2022 kl. 21.44 skrev Farzan Taj @.***>:

 I have the same issue, and I'm following the tutorial on the reference page. @drstormR Were you successful in finding a solution?

— Reply to this email directly, view it on GitHub, or unsubscribe. Triage notifications on the go with GitHub Mobile for iOS or Android. You are receiving this because you were mentioned.

drstormR avatar Mar 05 '22 21:03 drstormR

@drstormR, thank you, but I don't use "variable" as a column name anywhere in my code. Did you use faceting by any chance? By long data frame you are referring to the one passed to ggplot, correct?

FarzanT avatar Mar 05 '22 22:03 FarzanT

@drstormR just solved it, realized I had all NAs in one of my columns! Thanks!

FarzanT avatar Mar 05 '22 22:03 FarzanT