Using Altair, how can I plot in the same horizontal bar plot two variables that are in the same data frame?
I have a panda data frame that looks like this:
# initialize list of lists
data = [['AAA','71.15','FOUSA06C1Y'],
['AA','2.93','FOUSA06C1Y'],
['A','11.9','FOUSA06C1Y'],
['BBB','14.04','FOUSA06C1Y'],
['BB','0.0','FOUSA06C1Y'],
['B','0.0','FOUSA06C1Y'],
['Below B','0.0','FOUSA06C1Y'],
['Not Rated','-0.02','FOUSA06C1Y'],
['AAA','34.81744518','1404'],
['AA','47.24845367','1404'],
['A','16.66257244','1404'],
['BBB','1.271528716','1404'],
['BB / B','0.0','1404'],
['Below B','0.0','1404'],
['Short Term Rated','0.0','1404'],
['Not Rated','0.0','1404'],
['Nan','0.0','1404']]
# Create the pandas DataFrame
df = pd.DataFrame(data, columns=['index', 'value','fund'])
df['value'] = df['value'].astype(float)
I am able to separately horizontal bar plot these with below code:
gp_chart = alt.Chart(df).mark_bar().encode(
alt.X('value'),
alt.Y('index', axis=alt.Axis(grid=True)),
alt.Color('fund'),
alt.Row('fund')
)
gp_chart
Which will produce this separated graphs:
Picking part of this graph as an example (just picking A and AAA), I want to see these bars together like this:
Similar question here.