What

Init

library(kirkegaard)
## Loading required package: tidyverse
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.1 ──
## ✓ ggplot2 3.3.5     ✓ purrr   0.3.4
## ✓ tibble  3.1.6     ✓ dplyr   1.0.7
## ✓ tidyr   1.1.4     ✓ stringr 1.4.0
## ✓ readr   2.1.1     ✓ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## x dplyr::filter() masks stats::filter()
## x dplyr::lag()    masks stats::lag()
## Loading required package: weights
## Loading required package: Hmisc
## Loading required package: lattice
## Loading required package: survival
## Loading required package: Formula
## 
## Attaching package: 'Hmisc'
## The following objects are masked from 'package:dplyr':
## 
##     src, summarize
## The following objects are masked from 'package:base':
## 
##     format.pval, units
## Loading required package: assertthat
## 
## Attaching package: 'assertthat'
## The following object is masked from 'package:tibble':
## 
##     has_name
## Loading required package: magrittr
## 
## Attaching package: 'magrittr'
## The following object is masked from 'package:purrr':
## 
##     set_names
## The following object is masked from 'package:tidyr':
## 
##     extract
## Loading required package: psych
## 
## Attaching package: 'psych'
## The following object is masked from 'package:Hmisc':
## 
##     describe
## The following objects are masked from 'package:ggplot2':
## 
##     %+%, alpha
## Loading required package: metafor
## Loading required package: Matrix
## 
## Attaching package: 'Matrix'
## The following objects are masked from 'package:tidyr':
## 
##     expand, pack, unpack
## 
## Loading the 'metafor' package (version 3.0-2). For an
## introduction to the package please type: help(metafor)
## Loading required package: rlang
## 
## Attaching package: 'rlang'
## The following object is masked from 'package:magrittr':
## 
##     set_names
## The following object is masked from 'package:assertthat':
## 
##     has_name
## The following objects are masked from 'package:purrr':
## 
##     %@%, as_function, flatten, flatten_chr, flatten_dbl, flatten_int,
##     flatten_lgl, flatten_raw, invoke, list_along, modify, prepend,
##     splice
## 
## Attaching package: 'kirkegaard'
## The following object is masked from 'package:rlang':
## 
##     is_logical
## The following object is masked from 'package:psych':
## 
##     rescale
## The following object is masked from 'package:assertthat':
## 
##     are_equal
## The following objects are masked from 'package:purrr':
## 
##     is_logical, is_numeric
## The following object is masked from 'package:base':
## 
##     +
load_packages(
  readxl
)

theme_set(theme_bw())

Data

d = read_excel("202211331747359655220FERT1.xlsx", skip = 2) %>% 
  map_df(as.numeric)
## New names:
## * `` -> ...1
## Warning in .Primitive("as.double")(x, ...): NAs introduced by coercion
#divide by 1000
for (v in names(d)[-1]) d[[v]] = d[[v]] / 1000

names(d) = c(
  "year",
  "All_women",
  "1st_gen_western",
  "1st_gen_nonwestern",
  "2nd_gen_western",
  "2nd_gen_nonwestern",
  "Danish_women"
)

str(d)
## tibble [35 × 7] (S3: tbl_df/tbl/data.frame)
##  $ year              : num [1:35] 1986 1987 1988 1989 1990 ...
##  $ All_women         : num [1:35] 1.48 1.5 1.56 1.62 1.67 ...
##  $ 1st_gen_western   : num [1:35] 1.67 1.6 1.7 1.72 1.88 ...
##  $ 1st_gen_nonwestern: num [1:35] 3.05 3.34 3.28 3.37 3.29 ...
##  $ 2nd_gen_western   : num [1:35] 1.32 1.22 1.41 1.54 1.33 ...
##  $ 2nd_gen_nonwestern: num [1:35] NA NA NA NA NA ...
##  $ Danish_women      : num [1:35] 1.45 1.46 1.52 1.58 1.62 ...
#long
d_long = d %>% 
  pivot_longer(cols = -year)

Plot

d_long %>% 
  ggplot(aes(year, value, color = name)) +
  geom_line() +
  geom_vline(xintercept = 2015, linetype = "dashed") +
  scale_x_continuous(breaks = seq(0, 10000, by = 2))
## Warning: Removed 7 row(s) containing missing values (geom_path).

GG_save("figs/fert_rates_timeline.png")
## Warning: Removed 7 row(s) containing missing values (geom_path).