Health expenditure and life expectancy

Source: HealthExpenditure/healthexpenditure.Rmd

The graph emphasizes a descriptive comparison: the United States is an outlier in spending relative to life expectancy, while Mexico is highlighted as another reference country.

Code
from pathlib import Path
import pandas as pd
import matplotlib.pyplot as plt

root = Path("../../ROS-Examples")
health = pd.read_table(root / "HealthExpenditure/data/healthdata.txt", sep=r"\s+")
health.head()
country spending lifespan
0 Australia 3357 81.4
1 Austria 3763 80.1
2 Belgium 3595 79.8
3 Canada 3895 80.7
4 Czech 1626 77.0

All countries

Code
colors = health.country.where(health.country.isin(["USA", "Mexico"]), other="other")
colors = colors.map({"USA": "red", "Mexico": "red", "other": "black"})
fig, ax = plt.subplots(figsize=(8, 6))
for _, r in health.iterrows():
    ax.text(r.spending, r.lifespan, r.country, color=colors.loc[r.name], fontsize=8)
ax.set_xlim(0, 1.05*health.spending.max())
ax.set_xlabel("Health care spending (PPP US$)")
ax.set_ylabel("Life expectancy (years)")
Text(0, 0.5, 'Life expectancy (years)')

Less cluttered display

Code
remove = health.country.isin(["Netherlands", "Belgium", "Germany", "Ireland", "Iceland", "Greece", "Italy", "Sweden", "UK"])
fig, ax = plt.subplots(figsize=(8, 6))
for _, r in health.loc[~remove].iterrows():
    col = "red" if r.country in ["USA", "Mexico"] else "black"
    ax.text(r.spending, r.lifespan, r.country, color=col, fontsize=9)
for x in [2000, 4000, 6000]:
    ax.axvline(x, color="lightgray", linewidth=.7)
for y in [74, 76, 78, 80, 82]:
    ax.axhline(y, color="lightgray", linewidth=.7)
ax.set_xlim(0, 1.05*health.spending.max())
ax.set_xlabel("Health care spending (PPP US$)")
ax.set_ylabel("Life expectancy (years)")
Text(0, 0.5, 'Life expectancy (years)')