2025-06-11
ai_example.qmd
file in the examples
directoryBefore we can do any visualization, we need to load in data and prepare it
Take this step seriously, especially your variable names, as your code depends on it
Workflow options:
There are no universal answers to the best approach here; friction as you work often tells you what to do
In this approach, you prepare the data in a separate script or notebook
You can then load the data into your visualization notebook
Two options:
Example of (1) above provided in our examples/project-example
directory
When using separate scripts, you’ll often want to save a copy of your cleaned data to load later scripts/notebooks
A good option here is use the saveRDS
function to save your data as an R data object
This has a few benefits
readRDS
, which can save you a lot of time when working with large datasetsexamples/prams_1_data_prep.qmd
fileexamples
directoryggplot2
and the Grammar of Graphicsggplot2 workflow
ggplot2
WorkflowGeom | R Function | Stat/Transformation | Use for |
---|---|---|---|
Point | geom_point() |
Identity | Scatter plots |
Bar | geom_bar() |
Count | Bar plots |
AB Line | geom_abline() |
Slope | Line plots |
Horizontal line | geom_hline() |
Y intercept | Reference lines |
Vertical line | geom_vline() |
X intercept | Reference lines |
Smoother | geom_smooth() |
Smoothing function (GAM, Loess, etc.) | Showing patterns/trends |
You can use position/fill to move elements around and color code geoms by aspects of the data, such as categories.
For example, with a bar chart:
stack
: Stack bars on top of each otherfill
: Stack bars, but make them always fill up vertical space to 1dodge
: Put the bars next to each otherTip: When you reach for fill, always consider faceting in small multiples. The brain struggles with fills. More on this later.
identity
mappingggplot2
Conceptsprams_2_ggplot_concepts.qmd
fileThe PRAMS data we used comes pre-aggregated
In prams_3_iteration_aggregation.qmd
we will illustrate how statistical transformations work by showing:
We will also demonstrate the process of iterating on a figure to make it more informative and visually appealing.
RColorBrewer
package gives good default color schemes that are accessible (i.e., easy to read for everyone) and aesthetically pleasing.ggplot
by default picks out pleasing colors that are distinguishable from each other by the human eye.colors.R
file in the examples
directory, which implements TailwindCSS’s color paletteexamples/colors_and_accessibility.qmd
file, we will explore the use of color design systems and perceptually uniform colorsGraduate Summer Institute of Epidemiology and Biostatistics