Hello i have this data that I want to plot. In column ‘IPVA’ there is [0, 1, 2] as possible values; where 1 and 0 are the data that i want to plot as a grouped bars chart and the 2 i want to plot it as a line above them. Right now im using the next code to create both graphics but when I try to concat them I get this error and I dont know how to proceed:
base = alt.Chart(dataset_obj1).encode(x=alt.X('Periodo:N'))
bar = base.mark_bar(color='#2A629A').encode(
x=alt.X('IPVA:O', axis=None).title('Periodo'),
y=alt.Y('Total:Q', scale=alt.Scale(domain=[0, 0.38]), axis=alt.AxisConfig(titleColor='#2A629A')).title('IPVA nacional'),
color='IPVA:N',
column=alt.Column('Periodo:N', header=alt.Header(orient='bottom'))
).properties(
width=50,
height=300,
title='IPVA en relación al salario medio'
).transform_filter(
alt.FieldOneOfPredicate(field='IPVA', oneOf=[1, 0])
);
line = base.mark_line(color='red', point=True).encode(
x=alt.X('Periodo:O'),
y=alt.Y('Total:Q', scale=alt.Scale(domain=[0, 0.45]), axis=alt.AxisConfig(titleColor='red')).title('Salario medio nacional'),
color=alt.value('red')
).properties(
width=500,
height=300,
).transform_filter(
alt.FieldEqualPredicate(field='IPVA', equal=2)
);
(line + bar).resolve_scale(y='independent')
[........]
---> 28 (line + bar).resolve_scale(y='independent')
File ~anaconda3envsmt_pythonLibsite-packagesaltairvegalitev5api.py:1240, in TopLevelMixin.__add__(self, other)
1238 if not isinstance(other, TopLevelMixin):
1239 raise ValueError("Only Chart objects can be layered.")
-> 1240 return layer(self, other)
File ~anaconda3envsmt_pythonLibsite-packagesaltairvegalitev5api.py:3087, in _check_if_can_be_layered(spec)
3085 for channel in ["row", "column", "facet"]:
3086 if _get(encoding, channel) is not Undefined:
-> 3087 raise ValueError(
3088 "Faceted charts cannot be layered. Instead, layer the charts before faceting."
3089 )
3090 if isinstance(spec, (Chart, LayerChart)):
3091 return
ValueError: Faceted charts cannot be layered. Instead, layer the charts before faceting.
Can someone help me, I want to do something like this but with the grouped bars:
Thank you!
I tried to concat the graphs, create both graphics in a base but i couldn’t get what i want…