Ordering in facet wrapped boxplots

Hey,

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)) +
geom_boxplot()
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)

Hi!

To help us help you, could you please prepare a reproducible example (reprex) illustrating your issue? Please have a look at this guide, to see how to create one:

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.