Hi I plotted a facet plot using ggplot in R and here is the plot
The problem I have is, The facets(labels) are sorted alphabetically (Ex: E1, E10, E11,E13, E2, E3, I1, I10, I2) but I need them to be a custom order like E1, I1, E2, I2, E3, E10, I10, E11, E13.
How can I do that ?
Just being working on a similar problem. I have levels which look like this by default:
Note that the second level is out of place due to alphabetical order.
This is what I am doing to fix the order:
It replaces levels like "A1" with "A01" then reorders according to these. I'm sure that you could do this a lot more efficiently, but it does the job.
It could be adapted to address the original problem.
Don't rely on the default ordering of levels imposed by
factor()
or internally byggplot
if the grouping variable you supply is not a factor. Set the levels explicitly yourself.What if I want them in this arbitrary order?
To do this, set the levels the way you want them.
Now we can use this to have the panels drawn in the order we want:
Which produces: