p = ggplot(cases, aes(x="Specimen date", y="Daily lab-confirmed cases", group = 1)) + geom_point() + geom_line() + labs(title = "Daily COVID-19 Cases")
p.save(filename = date_today, height=5, width=15, units = 'in', dpi=1000)
This is my current code to plot a graph from a DataFrame containing COVID-19 cases in England, which is then saved. I'm trying to add a trend line that is similar to the Worldometer graphs (as shown below).
I cannot post images yet, so I will provide the example here.
This is what my graph currently looks like.
I am trying to achieve the '3-day moving average' and the '7-day moving average'.
See stat_smooth, you can smooth using a moving average.
For example you may end up adding code like
But this will not give you a legend, because the moving average is not a variable (with a corresponding value) in the dataframe, i.e. given what you want to plot the data is not tidy. So if you want a legend you will have to compute the moving average, create a tidy dataframe and plot the computed averages that are in tidy form.
How? Use pandas.melt e.g.