From 6021fe80324512533f70af22a59597d8e57d9fdb Mon Sep 17 00:00:00 2001
From: Chandrasekhar Ramakrishnan <cramakri@ethz.ch>
Date: Thu, 19 Mar 2020 15:31:26 +0000
Subject: [PATCH] feat: added log plot of dashboard

---
 notebooks/Dashboard.ipynb | 29 +++++++++++++++++++++++++++--
 1 file changed, 27 insertions(+), 2 deletions(-)

diff --git a/notebooks/Dashboard.ipynb b/notebooks/Dashboard.ipynb
index 70fc4a79..8d1861f3 100644
--- a/notebooks/Dashboard.ipynb
+++ b/notebooks/Dashboard.ipynb
@@ -224,7 +224,7 @@
    "metadata": {},
    "outputs": [],
    "source": [
-    "def facetted_growth_plot(df, variable, sort_order, ref_country, title):\n",
+    "def facetted_growth_plot(df, variable, sort_order, ref_country, title, yscale='linear'):\n",
     "    base = alt.Chart(df).properties(\n",
     "        width=250, height=150)\n",
     "    line = base.mark_line().encode(\n",
@@ -236,7 +236,7 @@
     "    label_loc = increase_df[increase_df['Country/Region'] == ref_country]['Days'].iloc[-2]\n",
     "    ref = base.mark_line(opacity=0.3).encode(\n",
     "        x='Days',\n",
-    "        y=variable,\n",
+    "        y=alt.Y(variable, scale=alt.Scale(type=yscale)),\n",
     "        color=alt.ColorValue('steelblue'),\n",
     "    ).transform_filter(f\"datum['Country/Region'] == '{ref_country}'\")\n",
     "    ref += ref.mark_text().encode(text='Country/Region:N').transform_filter(f\"datum['Days'] == {label_loc}\")\n",
@@ -312,6 +312,31 @@
     "  <a href=\"https://worldmap.harvard.edu/data/geonode:country_centroids_az8\">Harvard Worldmap</a>\n",
     "</p>'''))"
    ]
+  },
+  {
+   "cell_type": "code",
+   "execution_count": null,
+   "metadata": {},
+   "outputs": [],
+   "source": [
+    "# Same with log scale\n",
+    "sort_order = growth_in_value_df.groupby(\n",
+    "    'Country/Region').max().sort_values(\n",
+    "    'Confirmed', ascending=False).index.tolist()\n",
+    "chart = facetted_growth_plot(increase_df, \n",
+    "                             'Confirmed/100k',\n",
+    "                             sort_order,\n",
+    "                             'Italy',\n",
+    "                             \"Growth of cases/100k from case 100, compared to Italy (log scale)\",\n",
+    "                             'log')\n",
+    "display(chart)\n",
+    "display(HTML('''\n",
+    "<p style=\"font-size: smaller\">Data Sources: \n",
+    "  <a href=\"https://github.com/CSSEGISandData/COVID-19\">JHU CSSE</a>,\n",
+    "  <a href=\"https://data.worldbank.org/indicator/SP.POP.TOTL\">World Bank</a>,\n",
+    "  <a href=\"https://worldmap.harvard.edu/data/geonode:country_centroids_az8\">Harvard Worldmap</a>\n",
+    "</p>'''))"
+   ]
   }
  ],
  "metadata": {
-- 
GitLab