# Load the package
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.4     ✔ readr     2.1.5
## ✔ forcats   1.0.0     ✔ stringr   1.5.1
## ✔ ggplot2   3.5.1     ✔ tibble    3.2.1
## ✔ lubridate 1.9.4     ✔ tidyr     1.3.1
## ✔ purrr     1.0.2     
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag()    masks stats::lag()
## ℹ Use the conflicted package (<http://conflicted.r-lib.org/>) to force all conflicts to become errors
# Load the dataset
students <- read_delim("https://raw.githubusercontent.com/MarcoKuehne/marcokuehne.github.io/main/data/Viadrina/viadrina_students_2013_2025.csv", 
                       delim = ";", 
                       escape_double = FALSE, 
                       trim_ws = TRUE)
## Rows: 12 Columns: 7
## ── Column specification ────────────────────────────────────────────────────────
## Delimiter: ";"
## chr (1): term
## dbl (6): students, female, male, german, foreign, year
## 
## ℹ Use `spec()` to retrieve the full column specification for this data.
## ℹ Specify the column types or set `show_col_types = FALSE` to quiet this message.
# Create the plot
students %>% 
  ggplot(aes(x = year, y = students)) +     # Map year to x-axis and student numbers to y-axis
  geom_point() +                           # Add data points to the plot
  geom_smooth(method = "gam") +            # Add a smooth curve using a generalized additive model
  scale_x_continuous(breaks = scales::pretty_breaks(n = 9)) +  # Adjust x-axis to show readable year labels
  labs(title = "Student Numbers at Viadrina", 
       x = "Year (Winter Semester)", 
       y = "Student Numbers") +            # Add a title and axis labels
  theme_minimal() +                        # Use a clean, minimal theme for the plot
  geom_vline(xintercept = 2020.5,          # Add a vertical line at 2020.5 to indicate the Corona shock
             colour = "grey", 
             linetype = "solid", 
             lwd = 1.3) +
  geom_text(aes(x = 2020.7, y = 6500, 
                label = "Corona"), 
            colour = "red", 
            angle = 90, 
            vjust = 1)                     # Add a label for the vertical line
## Warning in geom_text(aes(x = 2020.7, y = 6500, label = "Corona"), colour = "red", : All aesthetics have length 1, but the data has 12 rows.
## ℹ Please consider using `annotate()` or provide this layer with data containing
##   a single row.
## `geom_smooth()` using formula = 'y ~ s(x, bs = "cs")'