$ show kjhealy/socviz
The kjhealy/socviz repository is an R package that provides curated datasets and utility functions for teaching data visualization using ggplot2, primarily as a companion to the book "Data Visualization: A Practical Introduction" (2nd edition, 2026). It bundles approximately 30 social science datasets sourced from US Census Bureau data (county demographics, poverty), the General Social Survey, US election results (historic through 2024), OECD economic indicators, FRED time series, opiate mortality, and others. These datasets are clean, well-documented, and compressed for efficient loading via `data()`. The package also includes small utility functions (e.g., `theme_socviz`, `%notin%`, `round_df`) that support common data visualization workflows. While the primary value lies in the ready-to-use datasets rather than complex transformations, the package is properly structured with roxygen2 documentation, pkgdown site, and CRAN CI checks. It is a solid resource for educators and students learning R graphics, though reproducibility of the raw data pipelines depends on external sources that may change over time.
The LLM identified 2 files worth highlighting for reuse:
Provides `theme_socviz()` and `theme_socviz_map()`, complete and configurable ggplot2 themes with sensible defaults for publication-quality figures. These can be extracted and reused in any ggplot2 project with minimal modification, demonstrating a clean pattern for building custom themes via `theme()` with control over fonts, grid lines, legend placement, and axis ticks. The map variant adapts the theme for spatial plots by removing axes and simplifying background elements.
Contains several small but reusable utility functions: `round_df` rounds all numeric columns in a data frame to a specified decimal, `center_df` mean-centers numeric columns, `prefix_replace` and `prefix_strip` handle common string prefix operations, and `int_to_year` converts integer years to Date objects. These functions are self-contained, parameterized, and solve recurring data preparation tasks without external dependencies beyond base R and dplyr.