John Lekberg


America, Life Expectancy at Birth

Created 2019-08-21.

Average life expectancy at birth from 1900 to 2015, by race and gender.

I used the NCHS's "Death rates and life expectancy at birth" dataset.

My idea with this graphic was to show to the idea that "life expectancy has gone up" over the past 100 years and see if the story was different for males compared to females, or black Americans compared to white Americans.

There is an interesting shift starting in the 1950's of female life expectancy beginning to rise above male life expectancy:

I'm not sure why this is. Some conjectures:

This graphic uses the "shadow context" technique I've been working on for a bit, by showing the life expectancy for all race-gender pairings in grey in the background, while emphasizing the facet's specific data in a bold black. The more I think about it, I think this "shadow context" technique is trying to overcome some limitations of static graphics and isn't needed in a dynamic graphic that can take user interaction.


Code used to create "America, Life Expectancy at Birth"


code.r
# -- Life Exptancy by Race and Gender
# DATA
df %>%
  filter(Race != "All Races") %>%
  filter(Sex != "Both Sexes") %>%
  #
  {
  ggplot((.)) +
    # SCALE
    scale_y_continuous(labels = function(x) sprintf("%syr", x)) +
    # COORD
    facet_grid(Race ~ Sex) +
    # GUIDE
    ylab("Life Expectancy at Birth (Average)") +
    ggtitle(
      "Average Life Expectancy at Birth from 1900 to 2015",
      subtitle = "In America. Faceted by race and gender."
      ) +
    # ELEMENT
    geom_line(
      aes(Year, Average.Life.Expectancy..Years., group=GroupID),
      data = (.) %>% mutate(GroupID = paste(Race, Sex)) %>% select(-c(Race, Sex)),
      color = "grey",
    ) +
    geom_line(aes(Year, Average.Life.Expectancy..Years.)) +
    # THEME
    theme_classic()
  }