import pandas as pd
from plotnine import ggplot, aes, geom_col
= pd.DataFrame({
df "x": ["b", "d", "c", "a"],
"y": [1, 2, 3, 4]
})
"reorder(x, y)", "y")) + geom_col() ggplot(df, aes(
plotnine.mapping._eval_environment.reorder
=np.median, ascending=True) reorder(x, y, fun
Reorder categorical by sorting along another variable
It is the order of the categories that changes. Values in x are grouped by categories and summarised to determine the new order.
Credit: Copied from plydata