# HistorySaid Global Economic Dataset — R Quick Start # Requires: readr, dplyr, ggplot2 library(readr) library(dplyr) library(ggplot2) # Load the unified dataset df <- read_csv("data/unified/all_indicators.csv", show_col_types = FALSE) cat(sprintf("Dataset: %s rows, %d countries, %d indicators\n", format(nrow(df), big.mark = ","), n_distinct(df$country_code), n_distinct(df$indicator_id))) cat(sprintf("Year range: %d–%d\n\n", min(df$year), max(df$year))) # --- Filter by country and indicator --- usa_gdp <- df %>% filter(country_code == "USA", indicator_id == "wb.NY.GDP.MKTP.CD", !is.na(value)) %>% arrange(year) cat("USA GDP (last 10 years):\n") print(tail(usa_gdp %>% select(year, value), 10)) # --- Compare countries --- countries <- c("USA", "CHN", "DEU", "JPN", "IND") gdp_compare <- df %>% filter(indicator_id == "wb.NY.GDP.MKTP.CD", country_code %in% countries, year == 2022) %>% arrange(desc(value)) cat("\nGDP comparison (2022):\n") print(gdp_compare %>% select(country_name, value)) # --- Plot time series --- plot_data <- df %>% filter(indicator_id == "wb.NY.GDP.MKTP.CD", country_code %in% countries, !is.na(value)) %>% mutate(value_t = value / 1e12) p <- ggplot(plot_data, aes(x = year, y = value_t, color = country_name)) + geom_line(linewidth = 0.8) + labs(title = "GDP (trillions USD)", x = "Year", y = "Trillions USD", color = "Country") + theme_minimal() ggsave("gdp_comparison.png", p, width = 10, height = 5, dpi = 150) cat("Plot saved to gdp_comparison.png\n")