library(rio)
library(tidyverse)
## ── Attaching core tidyverse packages ──────────────────────── tidyverse 2.0.0 ──
## ✔ dplyr     1.1.1     ✔ readr     2.1.4
## ✔ forcats   1.0.0     ✔ stringr   1.5.0
## ✔ ggplot2   3.4.3     ✔ tibble    3.2.1
## ✔ lubridate 1.9.2     ✔ tidyr     1.3.0
## ✔ purrr     1.0.1     
## ── 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
library(ggplot2)
countries <- import("https://byuistats.github.io/M335/data/heights/Height.xlsx", skip = 2) %>%
  tibble()
long_data <- countries %>%
  pivot_longer(
    cols = starts_with("18"), 
    names_to = "year",
    values_to = "height.cm")
long_data <- long_data %>%
  mutate(year_decade = floor(as.numeric(year) / 10) * 10)
long_data <- long_data %>%
  filter(!is.na(height.cm))
final_data <- long_data %>%
  rename(country = `Continent, Region, Country`) %>%
  select(Code, country, height.cm, year_decade)
write.csv(final_data, "reshaped_dataset.csv", row.names = FALSE)
countries <- read.csv("reshaped_dataset.csv")

countries <- countries %>%
  mutate(germany_highlight = ifelse(country == "Germany", "Germany", "Other"))
ggplot(data = countries, aes(x = year_decade, y = height.cm, color = germany_highlight)) +
  geom_point(aes(alpha = germany_highlight, size = germany_highlight)) + 
  labs(title = "Country Heights Over Decades", y = "Height in CM", x = "Decade") +
  scale_color_manual(values = c("Germany" = "orange", "Other" = "skyblue")) +  # Customize colors
  scale_alpha_manual(values = c("Germany" = 1, "Other" = 0.2)) +         # Make "Other" countries more transparent
  scale_size_manual(values = c("Germany" = 3, "Other" = 2)) +            # Make Germany bigger
  theme_minimal()