{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Population mobility and COVID-19\n", "\n", "In this notebook we want to show mobility dynamics in different countries in 2020, and how much it correlates with COVID-19.\n", "\n", "According to Apple, data show the relative volume of direction requests per country compared to the baseline volume on January 13, 2020. \"Day\" is defined as midnight to midnight, Pacific time. In many countries, relative volume has increased since January 13, consistent with normal, seasonal usage of Apple Maps. In addition, we need to consider the-day-of-the-week effects.\n", "\n", "In most dataframes I normalize mobility so that the volume on January 13 is 1. So, for example, mobility equals 2 if it has increased twice since the start time.\n", "\n", "Finally, [here](https://www.apple.com/covid19/mobility) you can find the mobility data, and [here](https://github.com/datasets/covid-19) is the disease data." ] }, { "cell_type": "code", "execution_count": 1, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:58.270835Z", "iopub.status.busy": "2024-04-17T07:39:58.270752Z", "iopub.status.idle": "2024-04-17T07:39:58.614732Z", "shell.execute_reply": "2024-04-17T07:39:58.614203Z" } }, "outputs": [], "source": [ "from itertools import product\n", "\n", "import numpy as np\n", "import pandas as pd\n", "import geopandas as gpd\n", "\n", "from lets_plot import *" ] }, { "cell_type": "code", "execution_count": 2, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:58.616408Z", "iopub.status.busy": "2024-04-17T07:39:58.616244Z", "iopub.status.idle": "2024-04-17T07:39:58.618415Z", "shell.execute_reply": "2024-04-17T07:39:58.618247Z" } }, "outputs": [ { "data": { "text/html": [ "\n", "
\n", " \n", " " ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "LetsPlot.setup_html()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Preparation" ] }, { "cell_type": "code", "execution_count": 3, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:58.633289Z", "iopub.status.busy": "2024-04-17T07:39:58.632884Z", "iopub.status.idle": "2024-04-17T07:39:58.635472Z", "shell.execute_reply": "2024-04-17T07:39:58.635210Z" } }, "outputs": [], "source": [ "def get_naturalearth_data(data_type=\"admin_0_countries\", columns=[\"NAME\", \"geometry\"]):\n", " import shapefile\n", " from shapely.geometry import shape\n", "\n", " naturalearth_url = \"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/master/\" + \\\n", " \"data/naturalearth/{0}/data.shp?raw=true\".format(data_type)\n", " sf = shapefile.Reader(naturalearth_url)\n", "\n", " gdf = gpd.GeoDataFrame(\n", " [\n", " dict(zip([field[0] for field in sf.fields[1:]], record))\n", " for record in sf.records()\n", " ],\n", " geometry=[shape(s) for s in sf.shapes()]\n", " )[columns]\n", " gdf.columns = [col.lower() for col in gdf.columns]\n", "\n", " return gdf" ] }, { "cell_type": "code", "execution_count": 4, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:58.636428Z", "iopub.status.busy": "2024-04-17T07:39:58.636352Z", "iopub.status.idle": "2024-04-17T07:39:58.637879Z", "shell.execute_reply": "2024-04-17T07:39:58.637697Z" } }, "outputs": [], "source": [ "def fix_country_name(name):\n", " UNIFORM_NAMES = {\n", " 'Czechia': 'Czech Republic',\n", " 'United States': 'United States of America',\n", " 'US': 'United States of America',\n", " 'Republic of Korea': 'South Korea',\n", " }\n", " return UNIFORM_NAMES[name] if name in UNIFORM_NAMES.keys() else name" ] }, { "cell_type": "code", "execution_count": 5, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:58.638840Z", "iopub.status.busy": "2024-04-17T07:39:58.638729Z", "iopub.status.idle": "2024-04-17T07:39:58.641304Z", "shell.execute_reply": "2024-04-17T07:39:58.641108Z" } }, "outputs": [], "source": [ "def get_prepared_mobility_data(*, target_cols, cc_dict):\n", " mobility_df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/\"\n", " \"master/data/covid19/applemobilitytrends.csv\")\n", " mobility_df = mobility_df[mobility_df.geo_type == 'country/region']\n", " mobility_df = mobility_df.drop(columns=['geo_type', 'alternative_name', 'sub-region', 'country'])\n", " mobility_df = mobility_df.set_index(['region', 'transportation_type'])\n", " mobility_df = mobility_df.T\n", " mobility_df = mobility_df.stack(level=0, future_stack=True)\n", " mobility_df.index = mobility_df.index.rename(names=['date', 'country'])\n", " mobility_df = mobility_df.reset_index()\n", " mobility_df.columns = [column_name.lower() for column_name in mobility_df.columns]\n", " mobility_df.country = mobility_df.country.apply(fix_country_name)\n", " mobility_df = mobility_df.fillna(0)\n", " mobility_df.date = pd.to_datetime(mobility_df.date)\n", " mobility_df = pd.melt(mobility_df, id_vars=['date', 'country'], value_vars=target_cols, \\\n", " var_name='mobility', value_name='mobility_value')\n", " mobility_df.mobility_value /= 100\n", " mobility_df['day'] = mobility_df.date.apply(lambda dt: dt.dayofyear)\n", " mobility_df['continent'] = mobility_df.country.apply(lambda c: cc_dict[c] if c in cc_dict.keys() else np.nan)\n", " mobility_df = mobility_df[~mobility_df.continent.isna()]\n", " return mobility_df" ] }, { "cell_type": "code", "execution_count": 6, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:58.642365Z", "iopub.status.busy": "2024-04-17T07:39:58.642210Z", "iopub.status.idle": "2024-04-17T07:39:58.643936Z", "shell.execute_reply": "2024-04-17T07:39:58.643759Z" } }, "outputs": [], "source": [ "def get_covid19_data():\n", " covid19_df = pd.read_csv(\"https://raw.githubusercontent.com/JetBrains/lets-plot-docs/\"\n", " \"master/data/covid19/countries_aggregated.csv\")\n", " covid19_df.columns = [column.lower() for column in covid19_df.columns]\n", " covid19_df.country = covid19_df.country.apply(fix_country_name)\n", " covid19_df.date = pd.to_datetime(covid19_df.date)\n", " covid19_df['recovery_index'] = covid19_df.recovered / covid19_df.confirmed\n", " covid19_df.recovery_index = covid19_df.recovery_index.fillna(0)\n", " return covid19_df" ] }, { "cell_type": "code", "execution_count": 7, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:58.644976Z", "iopub.status.busy": "2024-04-17T07:39:58.644806Z", "iopub.status.idle": "2024-04-17T07:39:58.646117Z", "shell.execute_reply": "2024-04-17T07:39:58.645950Z" } }, "outputs": [], "source": [ "TARGET_COLS = ['walking', 'driving']" ] }, { "cell_type": "code", "execution_count": 8, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:58.647040Z", "iopub.status.busy": "2024-04-17T07:39:58.646967Z", "iopub.status.idle": "2024-04-17T07:39:59.359110Z", "shell.execute_reply": "2024-04-17T07:39:59.358798Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
nameiso_a3continentpop_estgdp_mdgeometry
0FijiFJIOceania889953.05496MULTIPOLYGON (((180.00000 -16.06713, 180.00000...
1TanzaniaTZAAfrica58005463.063177POLYGON ((33.90371 -0.95000, 34.07262 -1.05982...
\n", "
" ], "text/plain": [ " name iso_a3 continent pop_est gdp_md \\\n", "0 Fiji FJI Oceania 889953.0 5496 \n", "1 Tanzania TZA Africa 58005463.0 63177 \n", "\n", " geometry \n", "0 MULTIPOLYGON (((180.00000 -16.06713, 180.00000... \n", "1 POLYGON ((33.90371 -0.95000, 34.07262 -1.05982... " ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "world_gdf = get_naturalearth_data(columns=[\"NAME\", \"ISO_A3\", \"CONTINENT\", \"POP_EST\", \"GDP_MD\", \"geometry\"])\n", "world_gdf['name'] = world_gdf['name'].apply(fix_country_name)\n", "world_gdf.head(2)" ] }, { "cell_type": "code", "execution_count": 9, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:39:59.360489Z", "iopub.status.busy": "2024-04-17T07:39:59.360398Z", "iopub.status.idle": "2024-04-17T07:40:00.442373Z", "shell.execute_reply": "2024-04-17T07:40:00.442067Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
datecountrymobilitymobility_valuedaycontinent
02020-01-13Albaniawalking1.013Europe
12020-01-13Argentinawalking1.013South America
\n", "
" ], "text/plain": [ " date country mobility mobility_value day continent\n", "0 2020-01-13 Albania walking 1.0 13 Europe\n", "1 2020-01-13 Argentina walking 1.0 13 South America" ] }, "execution_count": 9, "metadata": {}, "output_type": "execute_result" } ], "source": [ "mobility_df = get_prepared_mobility_data(target_cols=TARGET_COLS, \\\n", " cc_dict={r.iloc[0]: r.iloc[1] for i, r \\\n", " in world_gdf[['name', 'continent']].iterrows()})\n", "mobility_df.head(2)" ] }, { "cell_type": "code", "execution_count": 10, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:40:00.443797Z", "iopub.status.busy": "2024-04-17T07:40:00.443695Z", "iopub.status.idle": "2024-04-17T07:40:00.470077Z", "shell.execute_reply": "2024-04-17T07:40:00.469746Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
countrymobilitycontinentmobility_aggmobility_agg_value
0AlbaniadrivingEuropemobility_mean0.953083
1AlbaniawalkingEuropemobility_mean0.812417
\n", "
" ], "text/plain": [ " country mobility continent mobility_agg mobility_agg_value\n", "0 Albania driving Europe mobility_mean 0.953083\n", "1 Albania walking Europe mobility_mean 0.812417" ] }, "execution_count": 10, "metadata": {}, "output_type": "execute_result" } ], "source": [ "grouped_mobility_value = mobility_df.groupby(['country', 'mobility']).mobility_value\n", "combined_mobility_df = mobility_df.groupby(['country', 'mobility'])\\\n", " .continent.agg(lambda c: c.value_counts().index[0]).to_frame()\n", "\n", "combined_mobility_df = combined_mobility_df.join(grouped_mobility_value.min().to_frame(name='mobility_min'))\\\n", " .join(grouped_mobility_value.max().to_frame(name='mobility_max'))\\\n", " .join(grouped_mobility_value.mean().to_frame(name='mobility_mean'))\\\n", " .reset_index()\n", "\n", "combined_mobility_df = pd.melt(combined_mobility_df, id_vars=['country', 'mobility', 'continent'], \\\n", " value_vars=['mobility_mean', 'mobility_min', 'mobility_max'], \\\n", " var_name='mobility_agg', value_name='mobility_agg_value')\n", "combined_mobility_df.head(2)" ] }, { "cell_type": "code", "execution_count": 11, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:40:00.471375Z", "iopub.status.busy": "2024-04-17T07:40:00.471272Z", "iopub.status.idle": "2024-04-17T07:40:09.837221Z", "shell.execute_reply": "2024-04-17T07:40:09.836929Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", "\n", "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
datedaycountrycontinentmobilitymobility_valuerecovery_index
02020-01-2525AlbaniaEuropewalking0.97060.0
12020-01-2525AlbaniaEuropedriving1.02380.0
\n", "
" ], "text/plain": [ " date day country continent mobility mobility_value recovery_index\n", "0 2020-01-25 25 Albania Europe walking 0.9706 0.0\n", "1 2020-01-25 25 Albania Europe driving 1.0238 0.0" ] }, "execution_count": 11, "metadata": {}, "output_type": "execute_result" } ], "source": [ "c19_mobility_df = get_covid19_data()\n", "c19_mobility_df = c19_mobility_df.merge(mobility_df[mobility_df.day % 7 == 4], \\\n", " on=['date', 'country'], how='inner')\n", "c19_mobility_df = c19_mobility_df[['date', 'day', 'country', 'continent', 'mobility', \\\n", " 'mobility_value', 'recovery_index']]\n", "c19_mobility_df.head(2)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Comparison of Aggregated Mobility Values Countrywise" ] }, { "cell_type": "code", "execution_count": 12, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:40:09.838425Z", "iopub.status.busy": "2024-04-17T07:40:09.838352Z", "iopub.status.idle": "2024-04-17T07:40:09.853812Z", "shell.execute_reply": "2024-04-17T07:40:09.853626Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for continent in combined_mobility_df.continent.unique():\n", " local_df = combined_mobility_df[combined_mobility_df.continent == continent]\n", " local_df = local_df[local_df.mobility_agg == 'mobility_mean']\n", " local_df = local_df.sort_values(['mobility', 'mobility_agg_value'])\n", " display(\n", " ggplot() + \\\n", " geom_bar(aes(x='country', y='mobility_agg_value', fill='mobility'), \\\n", " data=local_df, stat='identity', color='white', \\\n", " tooltips=layer_tooltips().line('@country')\\\n", " .format('@mobility_agg_value', '.2f')\\\n", " .line('mean value|@mobility_agg_value')) + \\\n", " scale_fill_discrete(name='') + \\\n", " facet_grid(x='mobility') + \\\n", " ggtitle('Mean Mobility in %s' % continent) + \\\n", " ggsize(600, 150) + \\\n", " theme_void()\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "First of all, there is a minor correlation between \"driving\" and \"walking\" mobilities.\n", "\n", "Also, the biggest gap between min and max mobilities is seen in Europe and Asia.\n", "\n", "Finally, the most mobile citizens are Croatians, and the least mobile are Philippinos." ] }, { "cell_type": "code", "execution_count": 13, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:40:09.854823Z", "iopub.status.busy": "2024-04-17T07:40:09.854744Z", "iopub.status.idle": "2024-04-17T07:40:10.132124Z", "shell.execute_reply": "2024-04-17T07:40:10.131386Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": {}, "output_type": "execute_result" } ], "source": [ "multiindex_cols = ['mobility', 'mobility_agg', 'country']\n", "df1 = combined_mobility_df.set_index(multiindex_cols).mobility_agg_value.to_frame()\n", "df2 = pd.DataFrame(list(product(\n", " TARGET_COLS,\n", " combined_mobility_df.mobility_agg.unique(),\n", " set(world_gdf['name'].unique()) - set(combined_mobility_df.country.unique()),\n", " [np.nan]\n", ")), columns=['mobility', 'mobility_agg', 'country', 'mobility_agg_value']).set_index(multiindex_cols)\n", "df = pd.concat([df1, df2]).sort_index().reset_index()\n", "gdf = gpd.GeoDataFrame(\n", " df.merge(world_gdf[['name', 'geometry']], left_on='country', right_on='name', how='right'),\n", " geometry='geometry'\n", ")\n", "gdf = gdf[gdf.mobility_agg.isin(['mobility_min', 'mobility_max', 'mobility_mean'])]\n", "\n", "ggplot() + \\\n", " geom_map(aes(fill='mobility_agg_value'), data=gdf, color='white', \\\n", " tooltips=layer_tooltips().line('@country')\\\n", " .format('@mobility_agg_value', '.2f')\\\n", " .line('aggregated value|@mobility_agg_value')) + \\\n", " scale_fill_gradient(name='aggregated mobility', low='#1a9641', high='#d7191c', trans='log10') + \\\n", " facet_grid(x='mobility', y='mobility_agg') + \\\n", " coord_cartesian(xlim=[-10, 40],ylim=[30, 70]) + \\\n", " ggtitle('Mobility by Country in Europe') + \\\n", " ggsize(600, 600) + \\\n", " theme_void() + theme(legend_position='bottom')" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "During the quarantine the whole of Europe more or less complied with self-isolation requirements.\n", "\n", "It seems that the most difference between countries from the mobility point of view corresponds to the period of peak mobility." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Mobility Variation Over Time Countrywise" ] }, { "cell_type": "code", "execution_count": 14, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:40:10.143067Z", "iopub.status.busy": "2024-04-17T07:40:10.142943Z", "iopub.status.idle": "2024-04-17T07:40:10.181953Z", "shell.execute_reply": "2024-04-17T07:40:10.181748Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" }, { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "metadata": {}, "output_type": "display_data" } ], "source": [ "for continent in c19_mobility_df.continent.unique():\n", " local_df = c19_mobility_df[c19_mobility_df.continent == continent]\n", " display(\n", " ggplot() + \\\n", " geom_area(aes(x='date', y='mobility_value', group='country', color='country', fill='country'), \\\n", " data=local_df, alpha=.2, \\\n", " tooltips=layer_tooltips().line('@country')\\\n", " .format('@mobility_value', '.2f')\\\n", " .line('mobility value|@mobility_value')) + \\\n", " scale_x_datetime() + \\\n", " facet_grid(x='mobility') + \\\n", " ggtitle('Mobility Dynamics in %s' % continent) + \\\n", " ggsize(600, 300) + \\\n", " ylab('mobility') + theme(legend_position='none')\n", " )" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "As you can see on the plot, mobility plunged in the first quarter of the year. Then it rose again slowly.\n", "\n", "Some plots contain a small drooping tail at the end of the graph. This may indicate a new wave of self-isolation. Well, we shall see." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## About Connection between Mobility and CRI Index\n", "\n", "The CRI (COVID-19 Recovery) Index is the ratio of \\[registered\\] recovered to \\[registered\\] confirmed sick people. The higher value corresponds to a better state of healthcare (or at least so it should). The value falls within range \\[0, 1\\]." ] }, { "cell_type": "code", "execution_count": 15, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:40:10.183339Z", "iopub.status.busy": "2024-04-17T07:40:10.183232Z", "iopub.status.idle": "2024-04-17T07:40:10.261888Z", "shell.execute_reply": "2024-04-17T07:40:10.261574Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 15, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = c19_mobility_df.groupby(['country', 'mobility'])[['mobility_value', 'recovery_index']].corr().iloc[0::2, -1]\n", "df.index = df.index.droplevel(2)\n", "df = df.rename('covid_mobility_correlation')\n", "df = df.to_frame().reset_index()\n", "gdf = gpd.GeoDataFrame(\n", " df.merge(world_gdf[['name', 'geometry']], left_on='country', right_on='name', how='right'),\n", " geometry='geometry'\n", ")\n", "\n", "ggplot() + \\\n", " geom_map(aes(fill='covid_mobility_correlation'), data=gdf, color='white', \\\n", " tooltips=layer_tooltips().line('@name')\\\n", " .format('@covid_mobility_correlation', '.2f')\\\n", " .line('correlation value|@covid_mobility_correlation')) + \\\n", " scale_fill_gradient(name='correlation', low='#d7191c', high='#1a9641') + \\\n", " ggtitle('Correlation between Mobility and CRI') + \\\n", " ggsize(600, 450) + \\\n", " theme_void()" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The greener countries (Russia, Ukraine, US, Poland, Saudi Arabia, Canada, ...) show a positive correlation between mobility and CRI. More walking suggests a higher rate of recovery.\n", "\n", "In the redder countries (Argentina, Morocco, Chile, Ireland, ...) the correlation is negative: lower mobility coincides with better recovery." ] }, { "cell_type": "code", "execution_count": 16, "metadata": { "execution": { "iopub.execute_input": "2024-04-17T07:40:10.265048Z", "iopub.status.busy": "2024-04-17T07:40:10.264963Z", "iopub.status.idle": "2024-04-17T07:40:10.272021Z", "shell.execute_reply": "2024-04-17T07:40:10.271840Z" } }, "outputs": [ { "data": { "text/html": [ "
\n", " " ], "text/plain": [ "" ] }, "execution_count": 16, "metadata": {}, "output_type": "execute_result" } ], "source": [ "df = c19_mobility_df[c19_mobility_df.continent == 'North America']\n", "\n", "ggplot() + \\\n", " geom_path(aes(x='recovery_index', y='mobility_value'), data=df, color='#af8dc3') + \\\n", " geom_point(aes(x='recovery_index', y='mobility_value', fill='day'), \\\n", " data=df, shape=21, color='blue') + \\\n", " scale_fill_gradient(low='#91bfdb', high='#fc8d59') + \\\n", " facet_grid(x='mobility', y='country') + \\\n", " ggtitle('Combined Weekly Change of Mobility and CRI in North America') + \\\n", " ggsize(600, 450)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "These plots show the dynamics of interaction between mobility and CRI for North America. For most other countries the graphs would be similar. Most of them have the \"crescent\" shape: first no one recovers and mobility decreases rapidly, then recovery gradually rises, and finally, mobility starts growing along with CRI." ] } ], "metadata": { "kernelspec": { "display_name": "Python 3 (ipykernel)", "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.10.13" } }, "nbformat": 4, "nbformat_minor": 4 }