I have a dataframe which looks like below given:
Direction ID RY Value Part_of_prog
North 1 2016 29 0
North 2 2016 25 1
North 3 2016 25 0
North 4 2016 22 1
North 4 2017 22 1
North 4 2017 24 1
North 4 2017 25 0
North 4 2017 26 0
North 5 2018 26 0
North 5 2018 26 1
North 5 2018 20 1
North 5 2018 22 0
South 6 2018 22 0
South 6 2018 22 1
South 6 2018 24 1
South 6 2018 24 0
South 7 2017 24 0
South 7 2017 24 1
South 7 2017 19 1
South 7 2017 18 0
South 7 2016 13 0
South 7 2016 13 1
South 7 2016 14 1
South 7 2016 19 0
East 1 2016 29 0
East 2 2016 15 1
East 3 2016 25 0
East 4 2016 22 1
East 4 2017 22 1
East 4 2017 14 1
East 4 2017 25 0
East 4 2017 26 0
East 5 2018 16 0
East 5 2018 26 1
East 5 2018 10 1
East 5 2018 22 0
I am plotting bar plot in Facet grid using seaborn using following code:
g = sns.FacetGrid(df,col='Direction')
g = g.map_dataframe(sns.barplot,"RY","Value",hue='Part_of_prog',ci=None,palette = sns.color_palette("bright"))
for ax in g.axes.ravel():
ax.legend()
plt.show()
Which produces the following figure:
Now I want to change the bar plot to stacked bar. I want to use the facet grid to generate similar kind of layout. I used the following code to generate the figure but got an error:
g = sns.FacetGrid(df,col='Direction')
g = g.map_dataframe(df[['Value','RY']].plot.bar(stacked=True),hue='Part_of_prog',palette = sns.color_palette("bright"))
for ax in g.axes.ravel():
ax.legend()
plt.show()
Could anyone guide me how to generate the stacked bar plot in facegrid?
