18  Key R Packages for Data Science

R’s ecosystem now spans more than 20,000 CRAN packages. This section covers three package ecosystems that cover most of what the rest of this book needs: stats (built in, for statistical analysis), plotly (interactive visualization), and tidyverse (a bundle of packages for data manipulation and visualization). For managing package versions across a project reliably, renv and pak — mentioned in the Overview of R and RStudio — are worth adopting once a project grows beyond a single script.

18.1 stats: Statistical Analysis and Hypothesis Testing

stats ships with base R — no installation needed. It covers descriptive statistics, hypothesis testing (t-tests, ANOVA, chi-square), and regression and time-series analysis, all covered in depth from Topic 7 onward.

18.2 plotly: Interactive Visualizations

plotly builds interactive charts — zoomable, pannable, with hover tooltips — and layers on top of ggplot2 output.

An agribusiness analyst might use exactly this kind of interactive scatter plot to explore how yield tracks rainfall across a season, hovering over individual points to check which field each one belongs to.

18.3 tidyverse: A Unified Toolkit for Data Science

The tidyverse bundles several packages under one library(tidyverse) call — including dplyr, tidyr, ggplot2, readr, purrr, tibble, stringr, and forcats — for a consistent, structured approach to importing, manipulating, visualizing, and modeling data.

18.3.1 Data Manipulation with dplyr

18.3.2 Data Tidying with tidyr

18.3.3 Data Visualization with ggplot2

18.3.4 String Manipulation with stringr

18.3.5 Handling Factors with forcats

Summary

Concept Description
Key R Packages
stats Built-in package for descriptive statistics, hypothesis testing, and regression.
plotly Interactive, zoomable, hoverable charts that layer on top of ggplot2.
tidyverse Overview A bundle of packages (dplyr, tidyr, ggplot2, readr, purrr, tibble, stringr, forcats) for a consistent data-science workflow.
dplyr and tidyr dplyr filters and summarizes data; tidyr reshapes between wide and long formats.
ggplot2, stringr, and forcats ggplot2 builds layered visualizations; stringr manipulates text; forcats manages categorical factor levels.