Skip to content

Instantly share code, notes, and snippets.

@USMortality
Last active February 13, 2025 03:35
Show Gist options
  • Save USMortality/119f39152412264ddcc93c291a893b39 to your computer and use it in GitHub Desktop.
Save USMortality/119f39152412264ddcc93c291a893b39 to your computer and use it in GitHub Desktop.
Rate of Death Births per All Births [Germany]
library(readr)
library(dplyr)
library(tsibble)
library(ggplot2)
library(tidyr)
library(scales)
sf <- 2
width <- 600 * sf
height <- 335 * sf
options(vsc.dev.args = list(width = width, height = height, res = 72 * sf))
# 1. Dead Births
# https://www-genesis.destatis.de/genesis//online?operation=table&code=12612-0018
dead_births <- read_delim(
"https://apify.mortality.watch/destatis-genesis/12612-0018.csv.gz",
delim = ";",
col_names = c("year", "total", "rate"),
col_types = "ii",
skip = 6
)
ts <- dead_births |>
filter(!is.na(year)) |>
mutate(total = as.numeric(total), rate = rate / 10) |>
as_tsibble(index = year)
chart <- ggplot(ts |> filter(year > 1990), aes(x = year)) +
geom_line(aes(y = rate), color = "black") +
labs(
title = "Rate of Death Births per All Births [Germany]",
subtitle = "Source: Destatis/Genesis: 12612-0018",
y = "Dead Births per all Births (Life + Dead)", x = "Year"
) +
scale_y_continuous(labels = number_format(accuracy = 0.1))
ggplot2::ggsave(
filename = "chart1.png", plot = chart, width = width, height = height,
units = "px", dpi = 72 * sf, device = grDevices::png, type = c("cairo")
)
@USMortality
Copy link
Author

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment