diff --git a/.renku/workflow/b1c0a33b463d406a820ff0a61fb3a526_papermill.cwl b/.renku/workflow/b1c0a33b463d406a820ff0a61fb3a526_papermill.cwl new file mode 100644 index 0000000000000000000000000000000000000000..335e476c4a827ba842a68d5ded0cab96ecc5ad9e --- /dev/null +++ b/.renku/workflow/b1c0a33b463d406a820ff0a61fb3a526_papermill.cwl @@ -0,0 +1,91 @@ +arguments: [] +baseCommand: +- papermill +class: CommandLineTool +cwlVersion: v1.0 +hints: [] +inputs: + input_1: + default: ts_folder + inputBinding: + position: 1 + prefix: -p + separate: true + shellQuote: true + streamable: false + type: string + input_2: + default: + class: Directory + listing: [] + path: ../../data/covid-19_jhu-csse + inputBinding: + position: 2 + separate: true + shellQuote: true + streamable: false + type: Directory + input_3: + default: rates_folder + inputBinding: + position: 3 + prefix: -p + separate: true + shellQuote: true + streamable: false + type: string + input_4: + default: + class: Directory + listing: [] + path: ../../data/covid-19_rates + inputBinding: + position: 4 + separate: true + shellQuote: true + streamable: false + type: Directory + input_5: + default: + class: File + path: ../../notebooks/Dashboard.ipynb + inputBinding: + position: 5 + prefix: --inject-paths + separate: true + shellQuote: true + streamable: false + type: File + input_6: + default: runs/Dashboard.run.ipynb + inputBinding: + position: 6 + separate: true + shellQuote: true + streamable: false + type: string +outputs: + output_0: + outputBinding: + glob: $(inputs.input_6) + streamable: false + type: File +permanentFailCodes: [] +requirements: +- class: InlineJavascriptRequirement +- class: InitialWorkDirRequirement + listing: + - entry: '$({"listing": [], "class": "Directory"})' + entryname: runs + writable: true + - entry: $(inputs.input_2) + entryname: data/covid-19_jhu-csse + writable: false + - entry: $(inputs.input_4) + entryname: data/covid-19_rates + writable: false + - entry: $(inputs.input_5) + entryname: notebooks/Dashboard.ipynb + writable: false +successCodes: [] +temporaryFailCodes: [] diff --git a/runs/Dashboard.run.ipynb b/runs/Dashboard.run.ipynb new file mode 100644 index 0000000000000000000000000000000000000000..8ee68b5da01772bb9e712ece6093a1cbf2df62c1 --- /dev/null +++ b/runs/Dashboard.run.ipynb @@ -0,0 +1,587 @@ +{ + "cells": [ + { + "cell_type": "code", + "execution_count": 1, + "metadata": { + "papermill": { + "duration": 0.35409, + "end_time": "2020-03-13T17:04:15.061697", + "exception": false, + "start_time": "2020-03-13T17:04:14.707607", + "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.02437, + "end_time": "2020-03-13T17:04:15.106586", + "exception": false, + "start_time": "2020-03-13T17:04:15.082216", + "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.022646, + "end_time": "2020-03-13T17:04:15.137496", + "exception": false, + "start_time": "2020-03-13T17:04:15.114850", + "status": "completed" + }, + "tags": [ + "injected-parameters" + ] + }, + "outputs": [], + "source": [ + "# Parameters\n", + "PAPERMILL_INPUT_PATH = \"notebooks/Dashboard.ipynb\"\n", + "PAPERMILL_OUTPUT_PATH = \"runs/Dashboard.run.ipynb\"\n", + "ts_folder = \"./data/covid-19_jhu-csse/\"\n", + "rates_folder = \"./data/covid-19_rates/\"\n" + ] + }, + { + "cell_type": "code", + "execution_count": 4, + "metadata": { + "papermill": { + "duration": 0.021072, + "end_time": "2020-03-13T17:04:15.168525", + "exception": false, + "start_time": "2020-03-13T17:04:15.147453", + "status": "completed" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "# Read in the data" + ] + }, + { + "cell_type": "code", + "execution_count": 5, + "metadata": { + "papermill": { + "duration": 0.065756, + "end_time": "2020-03-13T17:04:15.243131", + "exception": false, + "start_time": "2020-03-13T17:04:15.177375", + "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.038039, + "end_time": "2020-03-13T17:04:15.289236", + "exception": false, + "start_time": "2020-03-13T17:04:15.251197", + "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.017688, + "end_time": "2020-03-13T17:04:15.314301", + "exception": false, + "start_time": "2020-03-13T17:04:15.296613", + "status": "completed" + }, + "tags": [] + }, + "outputs": [], + "source": [ + "# Compile data needed for the visualizations" + ] + }, + { + "cell_type": "code", + "execution_count": 8, + "metadata": { + "papermill": { + "duration": 0.040604, + "end_time": "2020-03-13T17:04:15.374996", + "exception": false, + "start_time": "2020-03-13T17:04:15.334392", + "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.034326, + "end_time": "2020-03-13T17:04:15.424734", + "exception": false, + "start_time": "2020-03-13T17:04:15.390408", + "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.009134, + "end_time": "2020-03-13T17:04:15.448316", + "exception": false, + "start_time": "2020-03-13T17:04:15.439182", + "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.041449, + "end_time": "2020-03-13T17:04:15.498158", + "exception": false, + "start_time": "2020-03-13T17:04:15.456709", + "status": "completed" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/html": [ + "<em>Data up to Mar 10 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.009938, + "end_time": "2020-03-13T17:04:15.526404", + "exception": false, + "start_time": "2020-03-13T17:04:15.516466", + "status": "completed" + }, + "tags": [] + }, + "source": [ + "## How are cases per 100,000 distributed geographically?" + ] + }, + { + "cell_type": "code", + "execution_count": 11, + "metadata": { + "papermill": { + "duration": 0.199352, + "end_time": "2020-03-13T17:04:15.733984", + "exception": false, + "start_time": "2020-03-13T17:04:15.534632", + "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.045428, + "end_time": "2020-03-13T17:04:15.799713", + "exception": false, + "start_time": "2020-03-13T17:04:15.754285", + "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.030132, + "end_time": "2020-03-13T17:04:15.844929", + "exception": false, + "start_time": "2020-03-13T17:04:15.814797", + "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.100208, + "end_time": "2020-03-13T17:04:15.958509", + "exception": false, + "start_time": "2020-03-13T17:04:15.858301", + "status": "completed" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "<div id=\"altair-viz-b79eb79d0e8f4b50be1688903bb8f9f0\"></div>\n", + "<script type=\"text/javascript\">\n", + " (function(spec, embedOpt){\n", + " const outputDiv = document.getElementById(\"altair-viz-b79eb79d0e8f4b50be1688903bb8f9f0\");\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-433f706ddfa6221156e78c265aebad1f\"}, \"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-433f706ddfa6221156e78c265aebad1f\": [{\"Country/Region\": \"Australia\", \"Confirmed\": 0.4281306826095598, \"Deaths\": 0.012003663998398872, \"Recovered\": 0.0840256479887921, \"Lat\": -23.1315375, \"Long\": 140.0609875}, {\"Country/Region\": \"Austria\", \"Confirmed\": 2.057185925638154, \"Deaths\": 0.0, \"Recovered\": 0.04521287748655284, \"Lat\": 47.5162, \"Long\": 14.5501}, {\"Country/Region\": \"Bahrain\", \"Confirmed\": 7.00887387149166, \"Deaths\": 0.0, \"Recovered\": 1.4017747742983322, \"Lat\": 26.0275, \"Long\": 50.55}, {\"Country/Region\": \"Belgium\", \"Confirmed\": 2.3375802000128174, \"Deaths\": 0.0, \"Recovered\": 0.008754982022519914, \"Lat\": 50.8333, \"Long\": 4.0}, {\"Country/Region\": \"Denmark\", \"Confirmed\": 4.519231399481772, \"Deaths\": 0.0, \"Recovered\": 0.01724897480718234, \"Lat\": 56.2639, \"Long\": 9.5018}, {\"Country/Region\": \"France\", \"Confirmed\": 2.663193607427707, \"Deaths\": 0.04926311045129727, \"Recovered\": 0.017913858345926282, \"Lat\": 47.0, \"Long\": 2.0}, {\"Country/Region\": \"Germany\", \"Confirmed\": 1.7569474368355689, \"Deaths\": 0.0024117329263357162, \"Recovered\": 0.021705596337021446, \"Lat\": 51.0, \"Long\": 9.0}, {\"Country/Region\": \"Hong Kong SAR\", \"Confirmed\": 1.61052207757348, \"Deaths\": 0.040263051939337005, \"Recovered\": 0.8723661253523016, \"Lat\": 22.3, \"Long\": 114.2}, {\"Country/Region\": \"Iran (Islamic Republic of)\", \"Confirmed\": 9.831263513326588, \"Deaths\": 0.3557445514023921, \"Recovered\": 3.3386198277660917, \"Lat\": 32.0, \"Long\": 53.0}, {\"Country/Region\": \"Italy\", \"Confirmed\": 16.794281862259982, \"Deaths\": 1.0441611838689575, \"Recovered\": 1.198054987513669, \"Lat\": 43.0, \"Long\": 12.0}, {\"Country/Region\": \"Japan\", \"Confirmed\": 0.4591829073311989, \"Deaths\": 0.007903320263876057, \"Recovered\": 0.07982353466514817, \"Lat\": 36.0, \"Long\": 138.0}, {\"Country/Region\": \"Mainland China\", \"Confirmed\": 5.798467757569664, \"Deaths\": 0.2251692718617392, \"Recovered\": 4.315696509732684, \"Lat\": 33.40693612903227, \"Long\": 111.54290322580646}, {\"Country/Region\": \"Malaysia\", \"Confirmed\": 0.4091525198482584, \"Deaths\": 0.0, \"Recovered\": 0.07612139904153642, \"Lat\": 2.5, \"Long\": 112.5}, {\"Country/Region\": \"Netherlands\", \"Confirmed\": 2.216932407413909, \"Deaths\": 0.02321395191009329, \"Recovered\": 0.0, \"Lat\": 52.1326, \"Long\": 5.2913}, {\"Country/Region\": \"Norway\", \"Confirmed\": 7.526810498997428, \"Deaths\": 0.0, \"Recovered\": 0.018817026247493568, \"Lat\": 60.472, \"Long\": 8.4689}, {\"Country/Region\": \"Republic of Korea\", \"Confirmed\": 14.550136054326911, \"Deaths\": 0.10457970809711876, \"Recovered\": 0.4783553314812655, \"Lat\": 36.0, \"Long\": 128.0}, {\"Country/Region\": \"Singapore\", \"Confirmed\": 2.837545551473431, \"Deaths\": 0.0, \"Recovered\": 1.3833034563432978, \"Lat\": 1.2833, \"Long\": 103.8333}, {\"Country/Region\": \"Spain\", \"Confirmed\": 3.6277054737195855, \"Deaths\": 0.07490837261367876, \"Recovered\": 0.06848765496107773, \"Lat\": 40.0, \"Long\": -4.0}, {\"Country/Region\": \"Sweden\", \"Confirmed\": 3.4861425832316537, \"Deaths\": 0.0, \"Recovered\": 0.009820119952765223, \"Lat\": 63.0, \"Long\": 16.0}, {\"Country/Region\": \"Switzerland\", \"Confirmed\": 5.7652500550986465, \"Deaths\": 0.035225560418118015, \"Recovered\": 0.035225560418118015, \"Lat\": 46.8182, \"Long\": 8.2275}, {\"Country/Region\": \"UK\", \"Confirmed\": 0.5745312032182892, \"Deaths\": 0.009024050312329149, \"Recovered\": 0.027072150936987446, \"Lat\": 55.0, \"Long\": -3.0}, {\"Country/Region\": \"US\", \"Confirmed\": 0.5104420019995022, \"Deaths\": 0.017116618031121033, \"Recovered\": 0.004584808401193134, \"Lat\": 38.77302746113991, \"Long\": -93.61047823834195}]}}, {\"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.062654, + "end_time": "2020-03-13T17:04:16.037936", + "exception": false, + "start_time": "2020-03-13T17:04:15.975282", + "status": "completed" + }, + "tags": [] + }, + "outputs": [ + { + "data": { + "text/html": [ + "\n", + "<div id=\"altair-viz-a0d74fce564e44529149f3e190cf879e\"></div>\n", + "<script type=\"text/javascript\">\n", + " (function(spec, embedOpt){\n", + " const outputDiv = document.getElementById(\"altair-viz-a0d74fce564e44529149f3e190cf879e\");\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-433f706ddfa6221156e78c265aebad1f\"}, \"height\": 900, \"$schema\": \"https://vega.github.io/schema/vega-lite/v4.0.2.json\", \"datasets\": {\"data-433f706ddfa6221156e78c265aebad1f\": [{\"Country/Region\": \"Australia\", \"Confirmed\": 0.4281306826095598, \"Deaths\": 0.012003663998398872, \"Recovered\": 0.0840256479887921, \"Lat\": -23.1315375, \"Long\": 140.0609875}, {\"Country/Region\": \"Austria\", \"Confirmed\": 2.057185925638154, \"Deaths\": 0.0, \"Recovered\": 0.04521287748655284, \"Lat\": 47.5162, \"Long\": 14.5501}, {\"Country/Region\": \"Bahrain\", \"Confirmed\": 7.00887387149166, \"Deaths\": 0.0, \"Recovered\": 1.4017747742983322, \"Lat\": 26.0275, \"Long\": 50.55}, {\"Country/Region\": \"Belgium\", \"Confirmed\": 2.3375802000128174, \"Deaths\": 0.0, \"Recovered\": 0.008754982022519914, \"Lat\": 50.8333, \"Long\": 4.0}, {\"Country/Region\": \"Denmark\", \"Confirmed\": 4.519231399481772, \"Deaths\": 0.0, \"Recovered\": 0.01724897480718234, \"Lat\": 56.2639, \"Long\": 9.5018}, {\"Country/Region\": \"France\", \"Confirmed\": 2.663193607427707, \"Deaths\": 0.04926311045129727, \"Recovered\": 0.017913858345926282, \"Lat\": 47.0, \"Long\": 2.0}, {\"Country/Region\": \"Germany\", \"Confirmed\": 1.7569474368355689, \"Deaths\": 0.0024117329263357162, \"Recovered\": 0.021705596337021446, \"Lat\": 51.0, \"Long\": 9.0}, {\"Country/Region\": \"Hong Kong SAR\", \"Confirmed\": 1.61052207757348, \"Deaths\": 0.040263051939337005, \"Recovered\": 0.8723661253523016, \"Lat\": 22.3, \"Long\": 114.2}, {\"Country/Region\": \"Iran (Islamic Republic of)\", \"Confirmed\": 9.831263513326588, \"Deaths\": 0.3557445514023921, \"Recovered\": 3.3386198277660917, \"Lat\": 32.0, \"Long\": 53.0}, {\"Country/Region\": \"Italy\", \"Confirmed\": 16.794281862259982, \"Deaths\": 1.0441611838689575, \"Recovered\": 1.198054987513669, \"Lat\": 43.0, \"Long\": 12.0}, {\"Country/Region\": \"Japan\", \"Confirmed\": 0.4591829073311989, \"Deaths\": 0.007903320263876057, \"Recovered\": 0.07982353466514817, \"Lat\": 36.0, \"Long\": 138.0}, {\"Country/Region\": \"Mainland China\", \"Confirmed\": 5.798467757569664, \"Deaths\": 0.2251692718617392, \"Recovered\": 4.315696509732684, \"Lat\": 33.40693612903227, \"Long\": 111.54290322580646}, {\"Country/Region\": \"Malaysia\", \"Confirmed\": 0.4091525198482584, \"Deaths\": 0.0, \"Recovered\": 0.07612139904153642, \"Lat\": 2.5, \"Long\": 112.5}, {\"Country/Region\": \"Netherlands\", \"Confirmed\": 2.216932407413909, \"Deaths\": 0.02321395191009329, \"Recovered\": 0.0, \"Lat\": 52.1326, \"Long\": 5.2913}, {\"Country/Region\": \"Norway\", \"Confirmed\": 7.526810498997428, \"Deaths\": 0.0, \"Recovered\": 0.018817026247493568, \"Lat\": 60.472, \"Long\": 8.4689}, {\"Country/Region\": \"Republic of Korea\", \"Confirmed\": 14.550136054326911, \"Deaths\": 0.10457970809711876, \"Recovered\": 0.4783553314812655, \"Lat\": 36.0, \"Long\": 128.0}, {\"Country/Region\": \"Singapore\", \"Confirmed\": 2.837545551473431, \"Deaths\": 0.0, \"Recovered\": 1.3833034563432978, \"Lat\": 1.2833, \"Long\": 103.8333}, {\"Country/Region\": \"Spain\", \"Confirmed\": 3.6277054737195855, \"Deaths\": 0.07490837261367876, \"Recovered\": 0.06848765496107773, \"Lat\": 40.0, \"Long\": -4.0}, {\"Country/Region\": \"Sweden\", \"Confirmed\": 3.4861425832316537, \"Deaths\": 0.0, \"Recovered\": 0.009820119952765223, \"Lat\": 63.0, \"Long\": 16.0}, {\"Country/Region\": \"Switzerland\", \"Confirmed\": 5.7652500550986465, \"Deaths\": 0.035225560418118015, \"Recovered\": 0.035225560418118015, \"Lat\": 46.8182, \"Long\": 8.2275}, {\"Country/Region\": \"UK\", \"Confirmed\": 0.5745312032182892, \"Deaths\": 0.009024050312329149, \"Recovered\": 0.027072150936987446, \"Lat\": 55.0, \"Long\": -3.0}, {\"Country/Region\": \"US\", \"Confirmed\": 0.5104420019995022, \"Deaths\": 0.017116618031121033, \"Recovered\": 0.004584808401193134, \"Lat\": 38.77302746113991, \"Long\": -93.61047823834195}]}}, {\"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.520956, + "end_time": "2020-03-13T17:04:16.371464", + "environment_variables": {}, + "exception": null, + "input_path": "notebooks/Dashboard.ipynb", + "output_path": "runs/Dashboard.run.ipynb", + "parameters": { + "PAPERMILL_INPUT_PATH": "notebooks/Dashboard.ipynb", + "PAPERMILL_OUTPUT_PATH": "runs/Dashboard.run.ipynb", + "rates_folder": "./data/covid-19_rates/", + "ts_folder": "./data/covid-19_jhu-csse/" + }, + "start_time": "2020-03-13T17:04:13.850508", + "version": "1.1.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +} \ No newline at end of file