Use the forcats package to change the order of the factor levels, based on summarized information of one of the quantitative variables. Consider experimenting with a summary statistic beyond the most basic choice of the mean/median. Use the forcats package in the tidyverse for this, rather than the baseR function as.factor.
Can I order the factor levels on a quantitative variable that isn't shown in the plot? (i.e. a geom_bar plot of count vs continent but order the factors by mean lifeExp?) I am asking because if that is the case, then it is not immediately obvious on the plot what I am ordering by like it would be if I ordered by counts, or plotted mean lifeExp vs continent?
One of the points of this exercise was to understand when re-ordering factor levels might be useful.
If it is not obvious that your factor re-ordering had an effect, the re-ordering was probably unnecessary.
Therefore, I would suggest making a plot where re-ordering of the factor levels has an obvious beneficial effect on the plot (i.e. improves readability).
For the Gapminder questions:
Can I order the factor levels on a quantitative variable that isn't shown in the plot? (i.e. a
geom_bar
plot ofcount
vscontinent
but order the factors by meanlifeExp
?) I am asking because if that is the case, then it is not immediately obvious on the plot what I am ordering by like it would be if I ordered bycounts
, or plotted meanlifeExp
vscontinent
?