Skip to content

Instantly share code, notes, and snippets.

@ikashnitsky
Created November 26, 2016 00:36
Show Gist options
  • Save ikashnitsky/872d3a97390a60d26eeb64f0f5600067 to your computer and use it in GitHub Desktop.
Save ikashnitsky/872d3a97390a60d26eeb64f0f5600067 to your computer and use it in GitHub Desktop.
Explore gender gap in age-specific mortality rates in Sweden at various times: 1751, 1800, 1850, 1900, 1925, 1950, 1960, 1970, 1980, 1990, 2000, 2010
###############################################################################
#
# Sweden 26-11-2016
# HMD data: illustrate gender difference in mortality
# Ilya Kashnitsky, ilya.kashnitsky@gmail.com
#
################################################################################
# The code is written and tested on a x86_64-pc-linux-gnu (64-bit) machine
# R version 3.3.2
library(tidyverse) # version 1.0.0
library(viridis) # version 0.3.4
library(ggthemes) # version 3.2.0
library(magrittr) # version 1.5
# By using this data, I agree to the user agreement: http://www.mortality.org/Public/UserAgreement.php.
df_swe <- read_csv('http://www.rostock-retreat.org/files/application2017/SWE.csv')
df_selected <- df_swe %>% select(Year, Sex, Age, mx) %>%
filter(Year %in% c(1751, 1800, 1850, 1900, 1925, 1950, 1960, 1970, 1980, 1990, 2000, 2010)) %>%
spread(Sex, mx) %>%
transmute(year = Year, age = Age, value = m / f)
ggplot(df_selected)+
geom_hline(yintercept = 1, color = 'grey25', size = .5)+
geom_point(aes(age, value), size = 2, pch=1, color = 'grey50')+
stat_smooth(aes(age, value, group = 1, color = factor(year)), se = F)+
facet_wrap(~year, ncol = 3)+
theme_fivethirtyeight() +
xlab('Age')+
theme(legend.position = 'none')+
labs(title = 'Male-to-female age-specific mortality rate ratio, Sweden',
subtitle = 'Untill quite recent times, mortality of females was not much lower than that of males',
caption = '\nData: Human Mortality Database (https://mortality.org)')
ggsave('sweden.png', width = 7, height = 7)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment