Newer
Older
Chandrasekhar Ramakrishnan
committed
{
"cells": [
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"papermill": {
"duration": 0.318369,
"end_time": "2020-03-13T17:58:07.699048",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:07.380679",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:07.718472",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:07.749324",
Chandrasekhar Ramakrishnan
committed
"status": "completed"
},
"tags": [
"injected-parameters"
]
},
"outputs": [],
"source": [
"# Parameters\n",
"PAPERMILL_INPUT_PATH = \"/tmp/ajs106te/notebooks/Dashboard.ipynb\"\n",
Chandrasekhar Ramakrishnan
committed
"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"
Chandrasekhar Ramakrishnan
committed
]
},
{
"cell_type": "code",
"execution_count": 4,
"metadata": {
"papermill": {
"duration": 0.020625,
"end_time": "2020-03-13T17:58:07.801350",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:07.780725",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:07.811703",
Chandrasekhar Ramakrishnan
committed
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:07.914210",
Chandrasekhar Ramakrishnan
committed
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:07.980059",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.010484",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.063060",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.117599",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.135082",
Chandrasekhar Ramakrishnan
committed
"status": "completed"
},
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"<em>Data up to Mar 12 2020</em>"
Chandrasekhar Ramakrishnan
committed
],
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.195671",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.213479",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.450292",
Chandrasekhar Ramakrishnan
committed
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.508441",
Chandrasekhar Ramakrishnan
committed
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
"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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.557800",
Chandrasekhar Ramakrishnan
committed
"status": "completed"
},
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<div id=\"altair-viz-9d8bbc6305e34585bef05d17e261d227\"></div>\n",
Chandrasekhar Ramakrishnan
committed
"<script type=\"text/javascript\">\n",
" (function(spec, embedOpt){\n",
" const outputDiv = document.getElementById(\"altair-viz-9d8bbc6305e34585bef05d17e261d227\");\n",
Chandrasekhar Ramakrishnan
committed
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
" 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",
Chandrasekhar Ramakrishnan
committed
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
"</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",
Chandrasekhar Ramakrishnan
committed
"exception": false,
"start_time": "2020-03-13T17:58:08.679034",
Chandrasekhar Ramakrishnan
committed
"status": "completed"
},
"tags": []
},
"outputs": [
{
"data": {
"text/html": [
"\n",
"<div id=\"altair-viz-01c78ff6476e41d882dd62fc1875817d\"></div>\n",
Chandrasekhar Ramakrishnan
committed
"<script type=\"text/javascript\">\n",
" (function(spec, embedOpt){\n",
" const outputDiv = document.getElementById(\"altair-viz-01c78ff6476e41d882dd62fc1875817d\");\n",
Chandrasekhar Ramakrishnan
committed
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
" 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",
Chandrasekhar Ramakrishnan
committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
"</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",
Chandrasekhar Ramakrishnan
committed
"environment_variables": {},
"exception": null,
"input_path": "/tmp/ajs106te/notebooks/Dashboard.ipynb",
Chandrasekhar Ramakrishnan
committed
"output_path": "runs/Dashboard.run.ipynb",
"parameters": {
"PAPERMILL_INPUT_PATH": "/tmp/ajs106te/notebooks/Dashboard.ipynb",
Chandrasekhar Ramakrishnan
committed
"PAPERMILL_OUTPUT_PATH": "runs/Dashboard.run.ipynb",
"rates_folder": "/tmp/ajs106te/data/covid-19_rates",
"ts_folder": "/tmp/ajs106te/data/covid-19_jhu-csse"
Chandrasekhar Ramakrishnan
committed
},
"start_time": "2020-03-13T17:58:06.540479",
Chandrasekhar Ramakrishnan
committed
"version": "1.1.0"
}
},
"nbformat": 4,
"nbformat_minor": 4
}