<p><div><div><div><div data-width="100" data-show-faces="false" data-send="true" data-layout="button_count" data-height="21" data-href="https://www.r-bloggers.com/gender-gap-in-swedish-mortality/"></div></div><div></div></div><div></div></div>
<div>
(This article was first published on <strong><a href="https://ikashnitsky.github.io/2017/gender-gap-in-swedish-mortality/"> Ilya Kashnitsky</a></strong>, and kindly contributed to <a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers)</a> </div>
<h2>Why Sweden?</h2>
<p>Sweden, with its high quality statistical record since 1748, is the natural choice for any demographic study that aims to cover population dynamics during a long period of time.</p>
<h2>Data</h2>
<p>The data used for this visualization comes from <a target="_blank" rel="nofollow" href="http://www.mortality.org/">Human Mortality Database</a>. It can be easily accessed from an R session using <a target="_blank" rel="nofollow" href="https://cran.r-project.org/web/packages/HMDHFDplus/index.html"><code>HMDHFDplus</code></a> package by <a target="_blank" rel="nofollow" href="https://sites.google.com/site/timriffepersonal/about-me">Tim Riffe</a> (for examples see my previous posts – <a target="_blank" rel="nofollow" href="https://ikashnitsky.github.io/2017/hmd-all-sex-ratio/">one</a> and <a target="_blank" rel="nofollow" href="https://ikashnitsky.github.io/2017/hmd-male-mortality-rus-jpn/">two</a>). For this exercise, I will use the dataset for Sweden that was provided for an application task for <a target="_blank" rel="nofollow" href="http://www.rostock-retreat.org/">Rostock Retreat Visualization</a><sup><a target="_blank" rel="nofollow" href="https://ikashnitsky.github.io/2017/gender-gap-in-swedish-mortality/#fn:1">1</a></sup>.</p>
<div>
<pre><code>library(tidyverse)
library(viridis)
library(extrafont)

# download data
df_swe &lt;- read_csv(&quot;http://www.rostock-retreat.org/files/application2017/SWE.csv&quot;)
# copy at https://ikashnitsky.github.io/doc/misc/application-rostock-retreat/SWE.csv

years &lt;- c(1751, 1800, 1850, 1900, 1925, 1950, 1960, 1970, 1980, 1990, 2000, 2010)

# select years and calculate male-to-female arte-ratio of mortality
df_selected &lt;- df_swe %>% select(Year, Sex, Age, mx) %>% 
        filter(Year %in% years) %>% 
        spread(Sex, mx) %>% 
        transmute(year = Year, age = Age, value = m / f)
</code></pre>
</div>
<h2>Visualization</h2>
<div>
<pre><code>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)+
        labs(title = &quot;Male-to-female age-specific mortality rate ratio, Sweden&quot;,
             subtitle = &quot;Untill quite recent times, mortality of females was not much lower than that of males&quot;,
             caption = &quot;\nData: Human Mortality Database (https://mortality.org)
             Note: Colored lines are produced with loess smoothing&quot;,
             x = &quot;Age&quot;, y = &quot;Rate ratio&quot;)+
        theme_minimal(base_size = 15, base_family = &quot;Roboto Condensed&quot;) +
        theme(legend.position = 'none',
              plot.title = element_text(family = &quot;Roboto Mono&quot;))
</code></pre>
</div>
<p><a target="_blank" rel="nofollow" href="https://i1.wp.com/ikashnitsky.github.io/images/170225/sweden.png?ssl=1"><img alt="figure" src="https://i1.wp.com/ikashnitsky.github.io/images/170225/sweden.png?w=456&ssl=1" data-recalc-dims="1"></a></p>
<h2>Comment</h2>
<p>Today it is common knowledge that male mortality is always higher than female. There are more males being born, then eventually the sex ratio levels due to higher male mortality (see <a target="_blank" rel="nofollow" href="https://ikashnitsky.github.io/2017/hmd-all-sex-ratio/">my previous post</a>). Though, male mortality was not always much higher. Back in the days, when infant mortality was much higher and women used to have much higher fertility, there was almost no gender gap in age-specific mortality levels. Constant pregnancy and frequent childbirths had a strong negative impact on female health and survival statistics. We can see that only in the second half of the 20-th century gender gap in mortality became substantial in Sweden.</p>
<div>
<ol>
<li>
<p>By using this data, I agree to the <a target="_blank" rel="nofollow" href="http://www.mortality.org/Public/UserAgreement.php">user agreement</a> <a target="_blank" rel="nofollow" href="https://ikashnitsky.github.io/2017/gender-gap-in-swedish-mortality/#fnref:1">↩</a></p>
</li>
</ol>
</div>
<p>
<div>
<div>To <strong>leave a comment</strong> for the author, please follow the link and comment on their blog: <strong><a href="https://ikashnitsky.github.io/2017/gender-gap-in-swedish-mortality/"> Ilya Kashnitsky</a></strong>.</div>
<hr>
<a rel="nofollow" href="https://www.r-bloggers.com/">R-bloggers.com</a> offers <strong><a rel="nofollow" href="https://feedburner.google.com/fb/a/mailverify?uri=RBloggers">daily e-mail updates</a></strong> about <a title="The R Project for Statistical Computing" rel="nofollow" href="https://www.r-project.org/">R</a> news and <a title="R tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/tutorial">tutorials</a> on topics such as: <a title="Data science" rel="nofollow" href="https://www.r-bloggers.com/search/data%20science">Data science</a>, <a title="Big Data" rel="nofollow" href="https://www.r-bloggers.com/search/Big%20Data">Big Data, <a title="R jobs" rel="nofollow" href="https://www.r-users.com/">R jobs</a>, visualization (<a title="ggplot and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/ggplot2">ggplot2</a>, <a title="Boxplots using lattice and ggplot2 tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/boxplot">Boxplots</a>, <a title="Maps and gis" rel="nofollow" href="https://www.r-bloggers.com/search/map">maps</a>, <a title="Animation in R" rel="nofollow" href="https://www.r-bloggers.com/search/animation">animation</a>), programming (<a title="RStudio IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/RStudio">RStudio</a>, <a title="Sweave and literate programming" rel="nofollow" href="https://www.r-bloggers.com/search/sweave">Sweave</a>, <a title="LaTeX in R" rel="nofollow" href="https://www.r-bloggers.com/search/LaTeX">LaTeX</a>, <a title="SQL and databases" rel="nofollow" href="https://www.r-bloggers.com/search/SQL">SQL</a>, <a title="Eclipse IDE for R" rel="nofollow" href="https://www.r-bloggers.com/search/eclipse">Eclipse</a>, <a title="git and github, Version Control System" rel="nofollow" href="https://www.r-bloggers.com/search/git">git</a>, <a title="Large data in R using Hadoop" rel="nofollow" href="https://www.r-bloggers.com/search/hadoop">hadoop</a>, <a title="Web Scraping of google, facebook, yahoo, twitter and more using R" rel="nofollow" href="https://www.r-bloggers.com/search/Web+Scraping">Web Scraping</a>) statistics (<a title="Regressions and ANOVA analysis tutorials" rel="nofollow" href="https://www.r-bloggers.com/search/regression">regression</a>, <a title="principal component analysis tutorial" rel="nofollow" href="https://www.r-bloggers.com/search/PCA">PCA</a>, <a title="Time series" rel="nofollow" href="https://www.r-bloggers.com/search/time+series">time series</a>, <a title="finance trading" rel="nofollow" href="https://www.r-bloggers.com/search/trading">trading</a>) and more...
<img height="1" alt="" width="1" src="http://feeds.feedburner.com/~r/RBloggers/~4/hjTecvTMq7Y"></a></div>