Skip to content

Instantly share code, notes, and snippets.

@xpqz
Created May 17, 2022 14:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save xpqz/c4f13f8ee97f47103c7f1a481481d3e1 to your computer and use it in GitHub Desktop.
Save xpqz/c4f13f8ee97f47103c7f1a481481d3e1 to your computer and use it in GitHub Desktop.
Modifed version of Nic's OWID plot
{sp}←OwidCovidData;Causeway;InitCauseway;View;countries_to_plot;csv;data;date;dates;field;fields_to_plot;location;locations;miss;row;sp;values
miss ← ¯1E300 ⍝ missing value
csv ← {⎕CSV ⍵ ⍬ 4} 'covid_subset2.csv'
dates ← {⍵[⍋⍵]}∪date ← 20 1⎕DT csv[;2]
csv[;2] ← date
locations ← ∪location←csv[;1]
row ← csv[;1 2]⍳↑locations∘.{⍺ ⍵}dates ⍝ row for each [location;date]
csv ⍪← (⊂'')(⊂'')miss miss
data ← csv[row;3 4] ⍝ data[location;date;fields]
fields_to_plot ← 'New cases per million' 'New deaths per million'
countries_to_plot ← 'United States' 'Canada' 'United Kingdom' 'France' 'Denmark'
'InitCauseway' 'View'⎕CY'sharpplot'
InitCauseway ⍬
sp ← ⎕NEW Causeway.SharpPlot
sp.MissingValue ← miss
sp.SetTrellis ≢fields_to_plot
:For field :In ⍳≢fields_to_plot
sp.NewCell ⍝ move to next cell
sp.Heading ← field⊃fields_to_plot
sp.MarginBottom ← 70 ⍝ need more margin thand default for key
sp.SetKeyText ⊂countries_to_plot
sp.YAxisStyle ← Causeway.YAxisStyles.LogScale
sp.XAxisStyle ← Causeway.XAxisStyles.(Date+MonthlyTicks)
sp.XDateFormat ← 'MMM-yy'
values ← ↓data[;;field]
sp.DrawLineGraph values dates
sp.DrawKey ⍬
:EndFor
View sp
@xpqz
Copy link
Author

xpqz commented May 17, 2022

Dataset available here: https://github.com/xpqz/owidp

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