I have covid19 tracking time series data which I scraped from covid19 tracking site. I want to make an annotated grouped stacked barchart. To do so, I used matplotlib
and seaborn
for making plot, I figured out plotting data to render the corresponding barchart. I tried plot annotation in SO
but didn't get the correct annotated plot. Also, I have some issues of getting grouped stacked barchart for the time series data. Can anyone suggest a possible way of doing this? Any idea?
my attempt
here is the reproducible time series data that I scraped from covid19 tracking site:
import pandas as pd
from datetime import date
import matplotlib.pyplot as plt
import seaborn as sns
bigdf = pd.read_csv("coviddf.csv")
bigdf['run_date'] = pd.to_datetime(bigdf['run_date'])
for g, d in bigdf.groupby(['company']):
data = d.groupby(['run_date','county-state', 'company', 'est'], as_index=True).agg({'new': sum, 'confirmed': sum, 'death': sum}).stack().reset_index().rename(columns={'level_4': 'type', 0: 'val'})
print(f'{g}')
g = sns.FacetGrid(data, col='est', sharex=False, sharey=False, height=5, col_wrap=4)
g.map(sns.barplot, 'run_date', 'val', 'type', order=data.run_date.dt.date.unique(), hue_order=data['type'].unique())
g.add_legend()
g.set_xticklabels(rotation=90)
g.set(yscale='log')
plt.tight_layout()
plt.show()
I have a couple of issues from the above attempt. I need to make grouped stacked barchart where each group is each different company, and each stack barchart is individual establishment (a.k.a, est
column in coviddf.csv
), so each company might have multiple establishments, so I want to see the number of new, confirmed and death covid19 cases in grouped stacked barchart. Is there any way to make annotated grouped stacked barchart for this time series? Can anyone suggest a possible way of achieving this? How to make these plots in one page? Any idea?
desired output
I tried to make grouped stacked barchart like this post and second related post did. Here is the desired annotated grouped stacked barchart that I want to make:
Can anyone point me out how to make this happen from above current attempt? Any thoughts about this?