0

I am trying to reorder my facet's x axis, but I'm not sure how to write an optional level for it, since some of the subgroups have "A" and others "B" and some both and if i write both of them, all the facet subgroups have two of them, some leaving one blank. I thought i could use operators | and & in between "A" and "B", but it didn't work.

My minimal dataset:

df_full<-data.frame(Treatment=c(A, B, 1,10,100,1, 10,100,1, 10, 100), 
            mean=c(0.4901950, 0.4360639, 0.9008428,0.8278645,0.7890388,0.9541905,
                         0.8537885,0.8212504,1.3828724,0.7165685, 0.7985398), 
vector=c("G", "F", "A","B","C","D", "E", "F","G","A", "B"),
  upper =c(0.9046951, 0.9046951, 1.0990144, 0.9505348, 0.8273494, 1.0389074, 0.9227461, 0.9657371,    1.6864420, 0.7401891, 0.9046951),
  lower=c(0.9528077, 0.6923846, 0.7026713, 0.7051941, 0.7507282, 0.9528077, 0.7848309, 0.6767638, 1.0793029, 0.6929479, 0.6923846),
            p.value=c(0.05, 0.04, 0.0003, 0.6500, 1,0.02,0.0400,
                    0.3301,0.100,0.023, 0.05))

My current facet order level code:

Treatment_factor  = factor(df_full$Treatment, levels =c("A", "B", "1", "10", "100"))

ggplot(df_full, aes(x = Treatment_factor, y = mean, color = Treatment_factor, group = vector))

I attach modified picture with my current graph:

i need to remove the ones i have crossed in red

How do i add option OR and AND in my levels code?

Simona
  • 87
  • 2
  • 8
  • To help us to help would you mind making your issue reproducible by providing [a minimal reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) including a snippet of your data. – stefan Aug 17 '21 at 16:07
  • .. at least I would try with `facet_wrap(..., scales = "free_x")` which should only keep the groups present in the panel. – stefan Aug 17 '21 at 16:09
  • 1
    that actually worked! thank you so much – Simona Aug 17 '21 at 16:27

0 Answers0