Parameterized Reporting with Quarto

Registered dogs in Switzerland

quarto
params
Author

Jadey Ryan

Published

March 27, 2024

Modified

August 10, 2024


1 Setup

Code
# Attach packages
library(tidyverse)

# Load data
pets <- read_rds("data/pets.RDS")

2 Breeds of dogs in Switzerland

Code
breeds <- pets |>
  filter(pet_type == params$pet_type)

# Top 5 per date
breeds_top_5 <- breeds |>
  slice_max(order_by = count, n = 5, by = date)

# Top 5 overall (average across all dates)
breeds_avg <- breeds_top_5 |>
  summarize(
    "Average Number" = format(
      mean(count),
      big.mark = ",",
      digits = 1,
      justify = "right",
      scientific = FALSE
    ),
    .by = "breed"
  ) |>
  rename("Breed" = breed) |>
  head(5)

The breed with the largest average population in Switzerland from 2016 - 2023 was the Kreuzung.

Code
breeds_top_5 |>
  ggplot(
    aes(x = date, y = count, color = breed)
  ) +
  geom_line(linewidth = 1) +
  scale_x_date(date_labels = "%Y", date_breaks = "1 year") +
  scale_y_continuous(
    labels = \(x) format(x, big.mark = ",", scientific = FALSE)
  ) +
  labs(
    title = "Evolution by breed",
    subtitle = str_wrap(
      paste(
        "Number of registered and living",
        params$pet_type,
        "by breed. The evolution of the largest populations is presented."
      ),
      80
    ),
    color = NULL,
    caption = "Source: Identitas AG Animal Statistics"
  ) +
  xlab(NULL) +
  ylab(NULL) +
  scale_color_brewer(palette = "Dark2") +
  theme_minimal() +
  theme(
    plot.caption.position = "plot",
    legend.position = "top",
    panel.grid.major.x = element_blank(),
    panel.grid.minor.x = element_blank()
  )

3 My favorite breed: Australian Shepherd

Code
fave_breed <- breeds |>
  filter(breed == params$fave_breed)
Code
fave_breed |>
  ggplot(
    aes(x = date, y = count)
  ) +
  geom_line(linewidth = 1) +
  scale_x_date(date_labels = "%Y", date_breaks = "1 year") +
  scale_y_continuous(
    labels = \(x) format(x, big.mark = ",", scientific = FALSE)
  ) +
  labs(
    title = paste(params$fave_breed, "population"),
    caption = "Source: Identitas AG Animal Statistics"
  ) +
  xlab(NULL) +
  ylab(NULL) +
  scale_color_brewer(palette = "Dark2") +
  theme_minimal() +
  theme(
    plot.caption.position = "plot",
    legend.position = "top",
    panel.grid.major.x = element_blank(),
    panel.grid.minor.x = element_blank()
  )

4 Data source

Identitas AG is the leading service provider for animal health, welfare and food safety in Switzerland.

Dogs are obliged to be registered for licensing purposes at a local government level and this data is kept in the Amicus database. Other pets, such as pets, rodents, birds or fish, may be registered and this data is stored in the Anis database.

5 Tutorial video

Back to top