Marital fertility rate

library(swepophist)
library(ggplot2)
library(dplyr)
d <- filter(mfrt, age == "total") %>% 
  mutate(
    col = ifelse(county_code %in% c(9,2), "low", "norm"),
    col = ifelse(county_code %in% c(25,24), "high", col),
    col = ifelse(is.na(county_code), "total", col)
  )

ggplot(d, aes(to, fert, group = context, color = col)) + 
  xlim(1880,1961) + geom_line() + theme_minimal() + 
  scale_color_manual(values = c("red", "blue","grey","black")) + 
  theme(legend.position = "bottom")

Fertility rate

df1 <- pop_fert %>% 
  filter(context == "Sweden") %>% 
  group_by(end) %>% 
  summarise(tfr = (sum(fert)*5)/1000) %>% 
  mutate(rate = "Marital")

df2 <- d %>% filter(context == "Sweden") %>% 
  select(end = to, tfr = fert) %>% 
  mutate(rate = "TFR") %>% 
  rbind(df1)

ggplot(df2, aes(end, tfr, group = rate)) + 
  geom_line(aes(color = rate), size = 2) + 
  annotate("text", 
    x = c(1895,1935), 
    y = c(3.2,6.9), 
    label = c("TFR", "Martial"), color = c("red", "blue")) +
  theme_classic() +
  theme(legend.position = "none")

Age-specific fertility rates

d1 <- pop_fert %>% filter(context != "Sweden", end >= 1850)
d2 <- pop_fert %>% filter(context == "Sweden", end >= 1850)
ggplot() + 
  geom_line(data = d1, aes(end, fert, group = context), color = "grey") +
  geom_line(data = d2, aes(end, fert, group = context), color = "black", size = 1) +
  facet_wrap(~age_g, nrow = 1) +
  theme_classic()

Population by age

df <- pop_age %>%
  group_by(year) %>%
  summarise(p = sum(pop, na.rm = T))

ggplot(df, aes(year, p/1000000, 1)) + geom_line() + 
  geom_point() +
  theme_classic()

# cut by span
cuts <- pop_age %>% filter(year == 1750) %>% select(age) %>% distinct() %>% .$age
cuts <- c(cuts, 80)

df2 <- pop_age %>%
  mutate(age_g = cut(age, cuts, right = FALSE)) %>%
  group_by(year, age_g) %>%
  summarise(p = sum(pop, na.rm = T))

df3 <- df2 %>%
  filter(age_g %in% levels(age_g)[c(1:4)]) %>%
  ungroup()

ggplot(df3, aes(year, p, group = age_g, color = age_g)) + 
  geom_line() + 
  scale_color_grey() +
  theme_classic()


junkka/swepophist documentation built on May 20, 2019, 4:24 a.m.