Regression Analysis
Add trend lines with statistical confidence bands to scatter plots and line charts.
Basic Trend Line
Add a regression mark to show the linear relationship in your data:
type: scatter
x: temperature
y: ice_cream_sales
marks:
- type: dot
- type: regression
title: Temperature vs Ice Cream SalesThe regression line fits through your data points using ordinary least squares (OLS).
Configuration
| Parameter | Type | Default | Description |
|---|---|---|---|
type | string | - | 'regression' |
x | string | inherited | X-axis field |
y | string | inherited | Y-axis field |
stroke | string | '#4f46e5' | Line color |
strokeWidth | number | 2 | Line thickness |
strokeOpacity | number | 1 | Line opacity |
showConfidence | boolean | true | Display confidence bands |
confidenceLevel | number | 0.95 | Confidence interval (0-1) |
showEquation | boolean | false | Display equation and R² |
extendDomain | number | 0 | Extend line beyond data range |
Confidence Bands
Confidence bands show the uncertainty around the trend line. The default 95% band means: if we repeated this analysis, 95% of regression lines would fall within this region.
marks:
- type: dot
- type: regression
showConfidence: true
confidenceLevel: 0.95Widen bands for more conservative estimates:
marks:
- type: regression
confidenceLevel: 0.99Disable bands for a cleaner look:
marks:
- type: regression
showConfidence: falseDisplay Equation
Show the regression equation and R² coefficient:
marks:
- type: regression
showEquation: trueDisplays: y = 2.34x + 15.7 (R² = 0.87)
The R² value indicates fit quality:
- 0.9+ Strong relationship
- 0.7-0.9 Moderate relationship
- Below 0.7 Weak relationship
Grouped Regression
Add separate trend lines for each category:
type: scatter
x: study_hours
y: test_score
color: subject
marks:
- type: dot
- type: regressionEach color group gets its own regression line, revealing whether the relationship varies by category.
Styling
Custom Colors
marks:
- type: regression
stroke: "#ef4444"
strokeWidth: 3Dashed Line
marks:
- type: regression
strokeDasharray: "5,5"Semi-transparent Band
marks:
- type: regression
showConfidence: true
fillOpacity: 0.1Outlier Handling
Remove outliers before fitting to prevent skewed results:
marks:
- type: regression
removeOutliers: true
outlierThreshold: 2.5Points beyond 2.5 standard deviations from the mean are excluded from the fit (but still displayed).
Extend Beyond Data
Project the trend line beyond your data range:
marks:
- type: regression
extendDomain: 0.1Extends the line 10% beyond the data range on each side.
Examples
Sales Forecast
type: scatter
x: month
y: revenue
marks:
- type: dot
fill: "#6366f1"
- type: regression
stroke: "#dc2626"
showEquation: true
extendDomain: 0.2
title: Revenue Trend with ForecastA/B Test Analysis
type: scatter
x: time_on_page
y: conversion_rate
color: variant
marks:
- type: dot
r: 4
- type: regression
strokeWidth: 2
showConfidence: true
title: Conversion by Time on Page
subtitle: Comparing variants A and BScientific Data
type: scatter
x: concentration
y: absorption
marks:
- type: dot
symbol: cross
- type: regression
showEquation: true
showConfidence: true
confidenceLevel: 0.99
removeOutliers: true
title: Beer-Lambert Calibration CurveLimitations
- Only linear regression is supported (no polynomial, logarithmic, etc.)
- Requires numeric x and y fields
- Confidence bands assume normal distribution of residuals
- Very small datasets (< 5 points) produce unreliable estimates