probably this has been posted hundreds of times, however none of the solutions seem to work. I am trying to reorder the plots in a facet wrapped boxplot to not have them in an alphabetical, but in a senseful order. I understood I need to use factor() for this. Just whereever I put it, it just doesn't work. Can anybody just tell me where exactly to put it?
My code is:
p <- ggplot(Rfilefinal3, aes(x=Cohort, y=Value)) +
Rfilefinal3$Cohort <- factor (Rfilefinal3$Cohort, levels = c("Control", "Covid-19", "Celiac disease"))
p + facet_wrap( ~ Marker, scales="free", ) +
stat_compare_means(method = "wilcox.test", ref.group = "Control", label = "p.signif", hide.ns =TRUE)