Closed fkgruber closed 2 weeks ago
plotnine the respects order of categorical variables.
In your translation, this
# Combine the dataframes
df = pd.concat([df_a, df_b, df_c], ignore_index=True)
part assumes that df["value"]
is a categorical, but it is not.
Try
# Combine the dataframes
df = pd.concat([df_a, df_b, df_c], ignore_index=True)
df["value"] = df["value"].astype(pd.CategoricalDtype(
["<0", "0", "(0,1]", "(1,3]", "(0,2]", "(2,4]", "(0,2.3]", "(2.3,4.2]"]
))
yes that works thanks!
It appears that geom_bar does not respect the order of categorical variables. For example, I wanted to replicated the following R plot:
In plotnine the order of the categorical variables is not respected: