{ "cells": [ { "cell_type": "code", "execution_count": 1, "metadata": { "papermill": { "duration": 0.318369, "end_time": "2020-03-13T17:58:07.699048", "exception": false, "start_time": "2020-03-13T17:58:07.380679", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "import pandas as pd\n", "import os\n", "from IPython.display import display, HTML, Markdown" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "papermill": { "duration": 0.02116, "end_time": "2020-03-13T17:58:07.739632", "exception": false, "start_time": "2020-03-13T17:58:07.718472", "status": "completed" }, "tags": [ "parameters" ] }, "outputs": [], "source": [ "ts_folder = \"../data/covid-19_jhu-csse/\"\n", "rates_folder = \"../data/covid-19_rates/\"\n", "out_folder = None\n", "PAPERMILL_OUTPUT_PATH = None" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "papermill": { "duration": 0.021777, "end_time": "2020-03-13T17:58:07.771101", "exception": false, "start_time": "2020-03-13T17:58:07.749324", "status": "completed" }, "tags": [ "injected-parameters" ] }, "outputs": [], "source": [ "# Parameters\n", "PAPERMILL_INPUT_PATH = \"/tmp/ajs106te/notebooks/Dashboard.ipynb\"\n", "PAPERMILL_OUTPUT_PATH = \"runs/Dashboard.run.ipynb\"\n", "ts_folder = \"/tmp/ajs106te/data/covid-19_jhu-csse\"\n", "rates_folder = \"/tmp/ajs106te/data/covid-19_rates\"\n" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "papermill": { "duration": 0.020625, "end_time": "2020-03-13T17:58:07.801350", "exception": false, "start_time": "2020-03-13T17:58:07.780725", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Read in the data" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "papermill": { "duration": 0.088499, "end_time": "2020-03-13T17:58:07.900202", "exception": false, "start_time": "2020-03-13T17:58:07.811703", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "def read_jhu_covid_df(name):\n", " filename = os.path.join(ts_folder, f\"time_series_19-covid-{name}.csv\")\n", " df = pd.read_csv(filename)\n", " df = df.set_index(['Province/State', 'Country/Region', 'Lat', 'Long'])\n", " df.columns = pd.to_datetime(df.columns)\n", " return df\n", "\n", "\n", "jhu_frames_map = {\n", " \"confirmed\": read_jhu_covid_df(\"Confirmed\"),\n", " \"deaths\": read_jhu_covid_df(\"Deaths\"),\n", " \"recovered\": read_jhu_covid_df(\"Recovered\")\n", "}" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "papermill": { "duration": 0.046747, "end_time": "2020-03-13T17:58:07.960957", "exception": false, "start_time": "2020-03-13T17:58:07.914210", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "def read_rates_covid_df(name):\n", " filename = os.path.join(rates_folder, f\"ts_rates_19-covid-{name}.csv\")\n", " df = pd.read_csv(filename).drop(\"Unnamed: 0\", axis=1)\n", " df = df.set_index(['Country/Region'])\n", " df.columns = pd.to_datetime(df.columns)\n", " return df\n", "\n", "\n", "rates_frames_map = {\n", " \"confirmed\": read_rates_covid_df(\"confirmed\"),\n", " \"deaths\": read_rates_covid_df(\"deaths\"),\n", " \"recovered\": read_rates_covid_df(\"recovered\")\n", "}" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "papermill": { "duration": 0.019568, "end_time": "2020-03-13T17:58:07.999627", "exception": false, "start_time": "2020-03-13T17:58:07.980059", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Compile data needed for the visualizations" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "papermill": { "duration": 0.03619, "end_time": "2020-03-13T17:58:08.046674", "exception": false, "start_time": "2020-03-13T17:58:08.010484", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Compute geospatial coordinates\n", "country_coords_df = jhu_frames_map['confirmed'].reset_index([2,3])[['Lat', 'Long']]\n", "country_coords_df = country_coords_df.groupby(level='Country/Region').mean()" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "papermill": { "duration": 0.036248, "end_time": "2020-03-13T17:58:08.099308", "exception": false, "start_time": "2020-03-13T17:58:08.063060", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Identify countries with 100 or more cases\n", "case_count_ser = jhu_frames_map['confirmed'].iloc[:,-1].groupby(level='Country/Region').sum()\n", "countries_over_thresh = case_count_ser[case_count_ser > 99].index" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.009486, "end_time": "2020-03-13T17:58:08.127085", "exception": false, "start_time": "2020-03-13T17:58:08.117599", "status": "completed" }, "tags": [] }, "source": [ "# Questions About COVID-19 and Its Spread\n", "\n", "These plots should be taken with a large grain of salt. I am not an epidemiologist, so the analyses shown here are completely naive. There are large discrepencies in the data from different countries for a variety of reasons (rates of testing, demographics, etc.) so that make direct comparisons inaccurate. Nonetheless, I think there is a lot of interesting information in this data." ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "papermill": { "duration": 0.043858, "end_time": "2020-03-13T17:58:08.178940", "exception": false, "start_time": "2020-03-13T17:58:08.135082", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "<em>Data up to Mar 12 2020</em>" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "data_ts = jhu_frames_map['confirmed'].iloc[:,-1].name.strftime(\"%b %d %Y\")\n", "display(HTML(f\"<em>Data up to {data_ts}</em>\"))" ] }, { "cell_type": "markdown", "metadata": { "papermill": { "duration": 0.009732, "end_time": "2020-03-13T17:58:08.205403", "exception": false, "start_time": "2020-03-13T17:58:08.195671", "status": "completed" }, "tags": [] }, "source": [ "## How are cases per 100,000 distributed geographically?" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "papermill": { "duration": 0.215996, "end_time": "2020-03-13T17:58:08.429475", "exception": false, "start_time": "2020-03-13T17:58:08.213479", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "import altair as alt\n", "from vega_datasets import data" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "papermill": { "duration": 0.040087, "end_time": "2020-03-13T17:58:08.490379", "exception": false, "start_time": "2020-03-13T17:58:08.450292", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "# Compile the basic df\n", "map_df = pd.concat([\n", " rates_frames_map['confirmed'].iloc[:,-1],\n", " rates_frames_map['deaths'].iloc[:,-1],\n", " rates_frames_map['recovered'].iloc[:,-1],\n", " country_coords_df], axis=1)\n", "# Restrict to countries with 100 or more cases\n", "map_df = map_df.loc[countries_over_thresh].dropna()\n", "map_df = map_df.reset_index()\n", "map_df.columns = ['Country/Region', 'Confirmed', 'Deaths', 'Recovered', 'Lat', 'Long']" ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "papermill": { "duration": 0.034884, "end_time": "2020-03-13T17:58:08.543325", "exception": false, "start_time": "2020-03-13T17:58:08.508441", "status": "completed" }, "tags": [] }, "outputs": [], "source": [ "def map_of_variable(map_df, variable):\n", " # Data generators for the background\n", " sphere = alt.sphere()\n", " graticule = alt.graticule()\n", "\n", " # Source of land data\n", " source = alt.topo_feature(data.world_110m.url, 'countries')\n", "\n", " # Layering and configuring the components\n", " p = alt.layer(\n", " alt.Chart(sphere).mark_geoshape(fill='#cae6ef'),\n", " alt.Chart(graticule).mark_geoshape(stroke='white', strokeWidth=0.5),\n", " alt.Chart(source).mark_geoshape(fill='#dddddd', stroke='#aaaaaa'),\n", " alt.Chart(map_df).mark_circle(opacity=0.6).encode(\n", " longitude='Long:Q',\n", " latitude='Lat:Q',\n", " size=alt.Size(f'{variable}:Q', title=\"Cases\"),\n", " color=alt.value('steelblue'),\n", " tooltip=[\"Country/Region:N\", \"Confirmed:Q\", \"Deaths:Q\", \"Recovered:Q\"]\n", " )\n", " ).project(\n", " 'naturalEarth1'\n", " ).properties(width=600, height=400, title=f\"{variable} cases per 100,000\"\n", " ).configure_view(stroke=None)\n", " return p" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "papermill": { "duration": 0.103115, "end_time": "2020-03-13T17:58:08.660915", "exception": false, "start_time": "2020-03-13T17:58:08.557800", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "\n", "<div id=\"altair-viz-9d8bbc6305e34585bef05d17e261d227\"></div>\n", "<script type=\"text/javascript\">\n", " (function(spec, embedOpt){\n", " const outputDiv = document.getElementById(\"altair-viz-9d8bbc6305e34585bef05d17e261d227\");\n", " const paths = {\n", " \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n", " \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n", " \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.0.2?noext\",\n", " \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n", " };\n", "\n", " function loadScript(lib) {\n", " return new Promise(function(resolve, reject) {\n", " var s = document.createElement('script');\n", " s.src = paths[lib];\n", " s.async = true;\n", " s.onload = () => resolve(paths[lib]);\n", " s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " });\n", " }\n", "\n", " function showError(err) {\n", " outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", " throw err;\n", " }\n", "\n", " function displayChart(vegaEmbed) {\n", " vegaEmbed(outputDiv, spec, embedOpt)\n", " .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", " }\n", "\n", " if(typeof define === \"function\" && define.amd) {\n", " requirejs.config({paths});\n", " require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", " } else if (typeof vegaEmbed === \"function\") {\n", " displayChart(vegaEmbed);\n", " } else {\n", " loadScript(\"vega\")\n", " .then(() => loadScript(\"vega-lite\"))\n", " .then(() => loadScript(\"vega-embed\"))\n", " .catch(showError)\n", " .then(() => displayChart(vegaEmbed));\n", " }\n", " })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300, \"stroke\": null}}, \"layer\": [{\"data\": {\"sphere\": true}, \"mark\": {\"type\": \"geoshape\", \"fill\": \"#cae6ef\"}}, {\"data\": {\"graticule\": true}, \"mark\": {\"type\": \"geoshape\", \"stroke\": \"white\", \"strokeWidth\": 0.5}}, {\"data\": {\"url\": \"https://vega.github.io/vega-datasets/data/world-110m.json\", \"format\": {\"feature\": \"countries\", \"type\": \"topojson\"}}, \"mark\": {\"type\": \"geoshape\", \"fill\": \"#dddddd\", \"stroke\": \"#aaaaaa\"}}, {\"data\": {\"name\": \"data-af06d21f07e2679aa76ca6a14f5f1418\"}, \"mark\": {\"type\": \"circle\", \"opacity\": 0.6}, \"encoding\": {\"color\": {\"value\": \"steelblue\"}, \"latitude\": {\"field\": \"Lat\", \"type\": \"quantitative\"}, \"longitude\": {\"field\": \"Long\", \"type\": \"quantitative\"}, \"size\": {\"type\": \"quantitative\", \"field\": \"Confirmed\", \"title\": \"Cases\"}, \"tooltip\": [{\"type\": \"nominal\", \"field\": \"Country/Region\"}, {\"type\": \"quantitative\", \"field\": \"Confirmed\"}, {\"type\": \"quantitative\", \"field\": \"Deaths\"}, {\"type\": \"quantitative\", \"field\": \"Recovered\"}]}}], \"height\": 400, \"projection\": {\"type\": \"naturalEarth1\"}, \"title\": \"Confirmed cases per 100,000\", \"width\": 600, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.0.2.json\", \"datasets\": {\"data-af06d21f07e2679aa76ca6a14f5f1418\": [{\"Country/Region\": \"Australia\", \"Confirmed\": 0.5121563305983519, \"Deaths\": 0.012003663998398872, \"Recovered\": 0.0840256479887921, \"Lat\": -23.1315375, \"Long\": 140.0609875}, {\"Country/Region\": \"Austria\", \"Confirmed\": 3.4135722502347403, \"Deaths\": 0.01130321937163821, \"Recovered\": 0.04521287748655284, \"Lat\": 47.5162, \"Long\": 14.5501}, {\"Country/Region\": \"Bahrain\", \"Confirmed\": 12.424821863098854, \"Deaths\": 0.0, \"Recovered\": 2.230096231838256, \"Lat\": 26.0275, \"Long\": 50.55}, {\"Country/Region\": \"Belgium\", \"Confirmed\": 2.749064355071253, \"Deaths\": 0.026264946067559743, \"Recovered\": 0.008754982022519914, \"Lat\": 50.8333, \"Long\": 4.0}, {\"Country/Region\": \"Canada\", \"Confirmed\": 0.3157140090886777, \"Deaths\": 0.002698410334091263, \"Recovered\": 0.021587282672730104, \"Lat\": 50.795, \"Long\": -93.00628}, {\"Country/Region\": \"Denmark\", \"Confirmed\": 10.6426174560315, \"Deaths\": 0.0, \"Recovered\": 0.01724897480718234, \"Lat\": 59.07825, \"Long\": 1.2949999999999995}, {\"Country/Region\": \"France\", \"Confirmed\": 3.4096043718413016, \"Deaths\": 0.07165543338370511, \"Recovered\": 0.017913858345926282, \"Lat\": 27.399466666666665, \"Long\": -41.22323333333333}, {\"Country/Region\": \"Germany\", \"Confirmed\": 2.5057905104628087, \"Deaths\": 0.0036175993895035743, \"Recovered\": 0.03014666157919645, \"Lat\": 51.0, \"Long\": 9.0}, {\"Country/Region\": \"Iceland\", \"Confirmed\": 29.13110126875845, \"Deaths\": 0.0, \"Recovered\": 0.28282622591027623, \"Lat\": 64.9631, \"Long\": -19.0208}, {\"Country/Region\": \"Israel\", \"Confirmed\": 1.4745942051824668, \"Deaths\": 0.0, \"Recovered\": 0.045025777257479915, \"Lat\": 31.0, \"Long\": 35.0}, {\"Country/Region\": \"Italy\", \"Confirmed\": 20.62176968839136, \"Deaths\": 1.368496511980393, \"Recovered\": 1.7292368259002542, \"Lat\": 43.0, \"Long\": 12.0}, {\"Country/Region\": \"Japan\", \"Confirmed\": 0.5050221648616801, \"Deaths\": 0.012645312422201693, \"Recovered\": 0.09325917911373748, \"Lat\": 36.0, \"Long\": 138.0}, {\"Country/Region\": \"Malaysia\", \"Confirmed\": 0.4725870190495387, \"Deaths\": 0.0, \"Recovered\": 0.08246484896166446, \"Lat\": 2.5, \"Long\": 112.5}, {\"Country/Region\": \"Netherlands\", \"Confirmed\": 2.919154452694232, \"Deaths\": 0.02901743988761661, \"Recovered\": 0.0, \"Lat\": 52.1326, \"Long\": 5.2913}, {\"Country/Region\": \"Norway\", \"Confirmed\": 13.209552425740487, \"Deaths\": 0.0, \"Recovered\": 0.018817026247493568, \"Lat\": 60.472, \"Long\": 8.4689}, {\"Country/Region\": \"Qatar\", \"Confirmed\": 9.418778672002537, \"Deaths\": 0.0, \"Recovered\": 0.0, \"Lat\": 25.3548, \"Long\": 51.1839}, {\"Country/Region\": \"Singapore\", \"Confirmed\": 3.156769426014192, \"Deaths\": 0.0, \"Recovered\": 1.7025273308840587, \"Lat\": 1.2833, \"Long\": 103.8333}, {\"Country/Region\": \"Spain\", \"Confirmed\": 4.873324698324187, \"Deaths\": 0.11771315696435232, \"Recovered\": 0.3916637768086632, \"Lat\": 40.0, \"Long\": -4.0}, {\"Country/Region\": \"Sweden\", \"Confirmed\": 5.882251851706369, \"Deaths\": 0.009820119952765223, \"Recovered\": 0.009820119952765223, \"Lat\": 63.0, \"Long\": 16.0}, {\"Country/Region\": \"Switzerland\", \"Confirmed\": 7.655688464204314, \"Deaths\": 0.04696741389082401, \"Recovered\": 0.04696741389082401, \"Lat\": 46.8182, \"Long\": 8.2275}, {\"Country/Region\": \"US\", \"Confirmed\": 0.508302424745612, \"Deaths\": 0.012226155736515023, \"Recovered\": 0.0036678467209545055, \"Lat\": 38.88347448559672, \"Long\": -94.14907777777768}]}}, {\"mode\": \"vega-lite\"});\n", "</script>" ], "text/plain": [ "alt.LayerChart(...)" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "\n", "<p style=\"font-size: smaller\">Data Source: \n", " <a href=\"https://github.com/CSSEGISandData/COVID-19\">JHU CSSE</a> and\n", " <a href=\"https://data.worldbank.org/indicator/SP.POP.TOTL\">World Bank</a>\n", "</p>" ], "text/plain": [ "<IPython.core.display.HTML object>" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "display(map_of_variable(map_df, 'Confirmed'))\n", "display(HTML('''\n", "<p style=\"font-size: smaller\">Data Source: \n", " <a href=\"https://github.com/CSSEGISandData/COVID-19\">JHU CSSE</a> and\n", " <a href=\"https://data.worldbank.org/indicator/SP.POP.TOTL\">World Bank</a>\n", "</p>'''))" ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "papermill": { "duration": 0.048886, "end_time": "2020-03-13T17:58:08.727920", "exception": false, "start_time": "2020-03-13T17:58:08.679034", "status": "completed" }, "tags": [] }, "outputs": [ { "data": { "text/html": [ "\n", "<div id=\"altair-viz-01c78ff6476e41d882dd62fc1875817d\"></div>\n", "<script type=\"text/javascript\">\n", " (function(spec, embedOpt){\n", " const outputDiv = document.getElementById(\"altair-viz-01c78ff6476e41d882dd62fc1875817d\");\n", " const paths = {\n", " \"vega\": \"https://cdn.jsdelivr.net/npm//vega@5?noext\",\n", " \"vega-lib\": \"https://cdn.jsdelivr.net/npm//vega-lib?noext\",\n", " \"vega-lite\": \"https://cdn.jsdelivr.net/npm//vega-lite@4.0.2?noext\",\n", " \"vega-embed\": \"https://cdn.jsdelivr.net/npm//vega-embed@6?noext\",\n", " };\n", "\n", " function loadScript(lib) {\n", " return new Promise(function(resolve, reject) {\n", " var s = document.createElement('script');\n", " s.src = paths[lib];\n", " s.async = true;\n", " s.onload = () => resolve(paths[lib]);\n", " s.onerror = () => reject(`Error loading script: ${paths[lib]}`);\n", " document.getElementsByTagName(\"head\")[0].appendChild(s);\n", " });\n", " }\n", "\n", " function showError(err) {\n", " outputDiv.innerHTML = `<div class=\"error\" style=\"color:red;\">${err}</div>`;\n", " throw err;\n", " }\n", "\n", " function displayChart(vegaEmbed) {\n", " vegaEmbed(outputDiv, spec, embedOpt)\n", " .catch(err => showError(`Javascript Error: ${err.message}<br>This usually means there's a typo in your chart specification. See the javascript console for the full traceback.`));\n", " }\n", "\n", " if(typeof define === \"function\" && define.amd) {\n", " requirejs.config({paths});\n", " require([\"vega-embed\"], displayChart, err => showError(`Error loading script: ${err.message}`));\n", " } else if (typeof vegaEmbed === \"function\") {\n", " displayChart(vegaEmbed);\n", " } else {\n", " loadScript(\"vega\")\n", " .then(() => loadScript(\"vega-lite\"))\n", " .then(() => loadScript(\"vega-embed\"))\n", " .catch(showError)\n", " .then(() => displayChart(vegaEmbed));\n", " }\n", " })({\"config\": {\"view\": {\"continuousWidth\": 400, \"continuousHeight\": 300}}, \"layer\": [{\"mark\": \"bar\", \"encoding\": {\"x\": {\"type\": \"quantitative\", \"field\": \"Confirmed\"}, \"y\": {\"type\": \"nominal\", \"field\": \"Country/Region\", \"sort\": \"-x\"}}}, {\"mark\": {\"type\": \"text\", \"align\": \"left\", \"baseline\": \"middle\", \"dx\": 3}, \"encoding\": {\"text\": {\"type\": \"quantitative\", \"field\": \"Confirmed\", \"format\": \".3\"}, \"x\": {\"type\": \"quantitative\", \"field\": \"Confirmed\"}, \"y\": {\"type\": \"nominal\", \"field\": \"Country/Region\", \"sort\": \"-x\"}}}], \"data\": {\"name\": \"data-af06d21f07e2679aa76ca6a14f5f1418\"}, \"height\": 900, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.0.2.json\", \"datasets\": {\"data-af06d21f07e2679aa76ca6a14f5f1418\": [{\"Country/Region\": \"Australia\", \"Confirmed\": 0.5121563305983519, \"Deaths\": 0.012003663998398872, \"Recovered\": 0.0840256479887921, \"Lat\": -23.1315375, \"Long\": 140.0609875}, {\"Country/Region\": \"Austria\", \"Confirmed\": 3.4135722502347403, \"Deaths\": 0.01130321937163821, \"Recovered\": 0.04521287748655284, \"Lat\": 47.5162, \"Long\": 14.5501}, {\"Country/Region\": \"Bahrain\", \"Confirmed\": 12.424821863098854, \"Deaths\": 0.0, \"Recovered\": 2.230096231838256, \"Lat\": 26.0275, \"Long\": 50.55}, {\"Country/Region\": \"Belgium\", \"Confirmed\": 2.749064355071253, \"Deaths\": 0.026264946067559743, \"Recovered\": 0.008754982022519914, \"Lat\": 50.8333, \"Long\": 4.0}, {\"Country/Region\": \"Canada\", \"Confirmed\": 0.3157140090886777, \"Deaths\": 0.002698410334091263, \"Recovered\": 0.021587282672730104, \"Lat\": 50.795, \"Long\": -93.00628}, {\"Country/Region\": \"Denmark\", \"Confirmed\": 10.6426174560315, \"Deaths\": 0.0, \"Recovered\": 0.01724897480718234, \"Lat\": 59.07825, \"Long\": 1.2949999999999995}, {\"Country/Region\": \"France\", \"Confirmed\": 3.4096043718413016, \"Deaths\": 0.07165543338370511, \"Recovered\": 0.017913858345926282, \"Lat\": 27.399466666666665, \"Long\": -41.22323333333333}, {\"Country/Region\": \"Germany\", \"Confirmed\": 2.5057905104628087, \"Deaths\": 0.0036175993895035743, \"Recovered\": 0.03014666157919645, \"Lat\": 51.0, \"Long\": 9.0}, {\"Country/Region\": \"Iceland\", \"Confirmed\": 29.13110126875845, \"Deaths\": 0.0, \"Recovered\": 0.28282622591027623, \"Lat\": 64.9631, \"Long\": -19.0208}, {\"Country/Region\": \"Israel\", \"Confirmed\": 1.4745942051824668, \"Deaths\": 0.0, \"Recovered\": 0.045025777257479915, \"Lat\": 31.0, \"Long\": 35.0}, {\"Country/Region\": \"Italy\", \"Confirmed\": 20.62176968839136, \"Deaths\": 1.368496511980393, \"Recovered\": 1.7292368259002542, \"Lat\": 43.0, \"Long\": 12.0}, {\"Country/Region\": \"Japan\", \"Confirmed\": 0.5050221648616801, \"Deaths\": 0.012645312422201693, \"Recovered\": 0.09325917911373748, \"Lat\": 36.0, \"Long\": 138.0}, {\"Country/Region\": \"Malaysia\", \"Confirmed\": 0.4725870190495387, \"Deaths\": 0.0, \"Recovered\": 0.08246484896166446, \"Lat\": 2.5, \"Long\": 112.5}, {\"Country/Region\": \"Netherlands\", \"Confirmed\": 2.919154452694232, \"Deaths\": 0.02901743988761661, \"Recovered\": 0.0, \"Lat\": 52.1326, \"Long\": 5.2913}, {\"Country/Region\": \"Norway\", \"Confirmed\": 13.209552425740487, \"Deaths\": 0.0, \"Recovered\": 0.018817026247493568, \"Lat\": 60.472, \"Long\": 8.4689}, {\"Country/Region\": \"Qatar\", \"Confirmed\": 9.418778672002537, \"Deaths\": 0.0, \"Recovered\": 0.0, \"Lat\": 25.3548, \"Long\": 51.1839}, {\"Country/Region\": \"Singapore\", \"Confirmed\": 3.156769426014192, \"Deaths\": 0.0, \"Recovered\": 1.7025273308840587, \"Lat\": 1.2833, \"Long\": 103.8333}, {\"Country/Region\": \"Spain\", \"Confirmed\": 4.873324698324187, \"Deaths\": 0.11771315696435232, \"Recovered\": 0.3916637768086632, \"Lat\": 40.0, \"Long\": -4.0}, {\"Country/Region\": \"Sweden\", \"Confirmed\": 5.882251851706369, \"Deaths\": 0.009820119952765223, \"Recovered\": 0.009820119952765223, \"Lat\": 63.0, \"Long\": 16.0}, {\"Country/Region\": \"Switzerland\", \"Confirmed\": 7.655688464204314, \"Deaths\": 0.04696741389082401, \"Recovered\": 0.04696741389082401, \"Lat\": 46.8182, \"Long\": 8.2275}, {\"Country/Region\": \"US\", \"Confirmed\": 0.508302424745612, \"Deaths\": 0.012226155736515023, \"Recovered\": 0.0036678467209545055, \"Lat\": 38.88347448559672, \"Long\": -94.14907777777768}]}}, {\"mode\": \"vega-lite\"});\n", "</script>" ], "text/plain": [ "alt.LayerChart(...)" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "bars = alt.Chart(map_df).mark_bar().encode(\n", " x='Confirmed:Q',\n", " y=alt.Y(\"Country/Region:N\", sort='-x')\n", ")\n", "\n", "text = bars.mark_text(\n", " align='left',\n", " baseline='middle',\n", " dx=3 # Nudges text to right so it doesn't appear on top of the bar\n", ").encode(\n", " text=alt.Text('Confirmed:Q', format=\".3\")\n", ")\n", "\n", "(bars + text).properties(height=900)" ] } ], "metadata": { "kernelspec": { "display_name": "Python 3", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.7.6" }, "papermill": { "duration": 2.508313, "end_time": "2020-03-13T17:58:09.048792", "environment_variables": {}, "exception": null, "input_path": "/tmp/ajs106te/notebooks/Dashboard.ipynb", "output_path": "runs/Dashboard.run.ipynb", "parameters": { "PAPERMILL_INPUT_PATH": "/tmp/ajs106te/notebooks/Dashboard.ipynb", "PAPERMILL_OUTPUT_PATH": "runs/Dashboard.run.ipynb", "rates_folder": "/tmp/ajs106te/data/covid-19_rates", "ts_folder": "/tmp/ajs106te/data/covid-19_jhu-csse" }, "start_time": "2020-03-13T17:58:06.540479", "version": "1.1.0" } }, "nbformat": 4, "nbformat_minor": 4 }