2D Density Contour
When two continuous variables are measured across groups with large n (n > 100), a scatter plot overplots —points overlap so densely that the actual distribution is invisible. A 2D kernel density contour plot visualizes the joint distribution of both variables simultaneously, with contour levels showing where data density is highest, grouped by a categorical variable using color.
STEP 1 —When to Use
Use a 2D density contour when: n > 100 per group (overplotting prevents readable scatter); you have two continuous variables and a categorical grouping variable; you want to compare the joint distribution shape and overlap between groups (e.g., flow cytometry data, population surveys, large-scale genomic data).
Do not use when: n < 50 per group (individual points are more informative); groups are so distinct that contours do not overlap (a scatter plot with distinct colors is clearer); the two variables are on incommensurable scales without a meaningful joint distribution.
STEP 2 —Journal Requirement
- Contour levels must be labeled (e.g., "Contour levels at 25th, 50th, 75th, 90th percentile of each group's density").
- Bandwidth selection method must be stated (same requirement as for violin plots).
- n per group must be stated.
- Color palette must be accessible (colorblind-safe distinction between groups).
STEP 3 —Licklider Implementation
Input
- Two continuous variables (x and y axes)
- Categorical grouping variable (color)
- Bandwidth: MISE-optimal (default), user-specified, or diagonal bandwidth matrix
- Contour levels: percentile-based (default) or density value-based
Output
- Contour lines per group with distinct colors (up to 4 groups with accessible palette)
- Filled contours optional (lowest level filled, others outlined)
- Marginal density strips on x and y axes (optional)
- Individual scatter points plotted semi-transparently beneath contours (optional)
- Bandwidth and contour level definition in legend
STEP 4 —Draft Output (Draft / Needs review)
Joint distribution of [X variable] and [Y variable] is shown as 2D kernel
density contours for each group (n = 280 per group). Contour lines represent
the 50th, 75th, and 90th percentile density levels for each group.
Bandwidth was selected using the MISE-optimal plug-in estimator.
Marginal density estimates are shown on each axis. Correlation within
each group: Group A: r = 0.42 (p < 0.001); Group B: r = ~.18 (p = 0.003).