【发布时间】:2018-10-04 13:07:10
【问题描述】:
我有以下dataframe
import pandas as pd
from plotnine import *
df = pd.DataFrame({
'variable': ['gender', 'gender', 'age', 'age', 'age', 'income', 'income', 'income', 'income'],
'category': ['Female', 'Male', '1-24', '25-54', '55+', 'Lo', 'Lo-Med', 'Med', 'High'],
'value': [60, 40, 50, 30, 20, 10, 25, 25, 40],
})
df['variable'] = pd.Categorical(df['variable'], categories=['gender', 'age', 'income'])
我正在使用以下代码来获取堆积条形图
(ggplot(df, aes(x='variable', y='value', fill='category'))
+ geom_col()
)
以上代码取自here
如何更改每个类别的顺序。例如。我希望 age 1-24 位于 age 堆叠条的底部
【问题讨论】:
标签: python python-3.x pandas plotnine