Skip to content

Instantly share code, notes, and snippets.

@mbauman
Created March 17, 2020 18:16
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save mbauman/934d22b808b9fdf97848e63a31c24789 to your computer and use it in GitHub Desktop.
Save mbauman/934d22b808b9fdf97848e63a31c24789 to your computer and use it in GitHub Desktop.
import HTTP, CSV
using Plots, DataFrames
df = CSV.read(IOBuffer(String(HTTP.get("https://covid.ourworldindata.org/data/total_cases.csv").body)), normalizenames=true)
function doit(df, countries, alignment)
plot(legend=:topleft)
for country in countries
c = df[:, Symbol(country)]
plot!(df.date .- df.date[findfirst(coalesce.(c,0) .>= alignment)], c, label=string(country), yaxis=:log)
end
xlabel!("Days after $alignment cases")
xlims!(-1, last(xlims()))
ylims!(alignment*.9, last(ylims()))
end
doit(df, [:Italy, :United_States, :United_Kingdom, :China], 100)
@briochemc
Copy link

briochemc commented Mar 18, 2020

This is great, thanks for sharing! Here is the plot as of 18 March 2020 for those who just want to see it

I have a few questions/comments:

  • why import HTTP, CSV and not using HTTP, CSV?
  • The alignment (on alignment cases) cannot be perfect because the data is daily. What about "force" aligning it by linearly interpolating the data to every minute first? [EDIT: Oh actually it's just that the China data starts at 278 cases...]
  • I want to play with this so I forked it and want to make sure it's OK with you... Is it? 🙂

@mbauman
Copy link
Author

mbauman commented Mar 18, 2020

Absolutely. Consider it MIT licensed. import instead of using because those packages largely rely on API style like CSV.read anyhow and HTTP exports a stack that conflicts with Dataframes (I was playing with the JHU dataset, too, which requires some munging).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment