Last active
January 24, 2018 05:16
-
-
Save ikashnitsky/8df43c9a5dcd1798116ba09b336cdcf2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
############################################################################### | |
# | |
# Sex ratios 29-10-2016 | |
# HMD data: illustrate Russian male mortality specifics | |
# Ilya Kashnitsky, [email protected] | |
# | |
################################################################################ | |
# load required packages | |
library(dplyr) # version 0.5.0 | |
library(ggplot2) # version 2.1.0 | |
library(HMDHFDplus) # version 1.1.8 | |
# Read HMD data directly into R | |
# please note! the arguments "ik_user_hmd" and "ik_pass_hmd" are my login credidantials | |
# at the website of Human Mortality Database, which are stored locally at my computer. | |
# In order to access the data, you need to create an account at | |
# http://www.mortality.org/ | |
# and provide your own credidantials to the `readHMDweb()` function | |
# load LT for men, RUS and JPN | |
rus <- readHMDweb('RUS',"mltper_1x1",ik_user_hmd,ik_pass_hmd) | |
jpn <- readHMDweb('JPN',"mltper_1x1",ik_user_hmd,ik_pass_hmd) | |
# compare mortality rates for 2014 | |
ru <- rus %>% filter(Year == 2014) %>% transmute(age=Age,rus=mx) | |
jp <- jpn %>% filter(Year == 2014) %>% transmute(age=Age,jpn=mx) | |
df <- left_join(jp,ru,'age') %>% mutate(ru_rate=rus/jpn) | |
# plot | |
gg <- ggplot(df, aes(age,ru_rate)) + | |
geom_hline(yintercept = 1, color = 'red') + | |
geom_line(aes(group=1)) + | |
theme_minimal(base_size = 15) + | |
scale_y_continuous('mortality rate ratio', | |
breaks = 0:10, labels = 0:10, limits = c(0, 10)) + | |
annotate('text',x=c(0, 55), y = c(1.75,5), label = c('Japan','Russia'), | |
color = c('red','black'), hjust = 0, vjust = 1, size = 7) + | |
ggtitle('Compare age-specific mortality of males\nRussia and Japan, 2014, HMD') | |
ggsave('male_mortality_compare.png', gg, width = 10, height = 7, type = 'cairo-png') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment