Free graph maker & data converters

Line of Best Fit and R²: What They Really Tell You

By Plotiq Editorial Team · Published 14 November 2026 · Updated 14 November 2026 · 5 min read

A trendline with an equation and an R² value is one of the most requested features on any graph, and one of the most over-trusted. This guide explains how the line is found, what R² measures, why a high R² can still mean a bad fit, and how to choose between linear, exponential and other models.

How the line of best fit is found

Given a set of (x, y) points, the line of best fit is the straight line y = mx + b that comes closest to all of them. “Closest” has a precise meaning in ordinary least squares: for each point measure the vertical distance to the line (the residual), square it, add the squares up, and choose the m and b that make that total as small as possible. Squaring stops positive and negative residuals cancelling and punishes large misses more than small ones.

The result has a closed-form solution. The slope is m = Σ(x − x̄)(y − ȳ) / Σ(x − x̄)², and the intercept is b = ȳ − m x̄, so the line always passes through the point of means (x̄, ȳ). You never need to search for it; any spreadsheet or graphing tool gets the same answer.

What R² measures

R², the coefficient of determination, compares the fitted line with the simplest alternative: a horizontal line at the mean of y. It is calculated as 1 − SS_res / SS_tot, where SS_res is the sum of squared residuals around your line and SS_tot is the sum of squared deviations of y from its mean. R² = 0.95 means the line explains 95% of the variation in y that a flat mean-only model leaves unexplained.

For a straight-line fit, R² equals the square of the correlation coefficient r, so R² = 1 is a perfect fit and R² = 0 means the line is no better than the mean. For other models, such as exponential or power fits, R² is calculated against the same baseline but is not strictly comparable with a linear R².

What R² does not tell you

A high R² does not prove the model is correct. A curved relationship can have an R² of 0.9 for a straight line while systematically missing the points in the middle. R² also depends on the range of x: spreading the x values out raises R² without improving the model. It says nothing about causation, because two variables that both rise over time will correlate strongly even if one has no effect on the other. And it does not tell you the size of the errors in the units you care about; for that use the standard deviation of the residuals.

A famous demonstration, Anscombe’s quartet, consists of four small data sets that share the same mean, the same regression line and the same R² of about 0.67, yet one is a clean line, one is a curve, one is a line with an outlier and one is a single high-leverage point. Only the plots show the difference. Always look at the graph.

Check the residuals

The quickest diagnostic is to subtract the fitted values from the measured ones and look at the residuals. In a good fit they scatter randomly around zero with no pattern and roughly constant size. A curve in the residuals means the model is the wrong shape. A fan shape, where residuals grow with x, means the error is proportional to the signal, and a weighted fit or a log transform would do better. A single huge residual flags an outlier that may be dragging the line.

Choosing between linear, exponential, power and polynomial

Choose the model from what you know about the process, not from whichever has the highest R². A linear fit suits proportional relationships and calibration lines. An exponential fit, y = a·e^(kx), suits growth or decay at a constant percentage rate. A power fit, y = a·x^b, suits scaling laws. A logarithmic fit suits values that rise quickly then level off. A polynomial fit adds flexibility but can wiggle between points and extrapolate wildly; use second or third order only for describing a smooth curve.

Exponential and power fits are computed on the logarithm of y (and x), so points with zero or negative values must be left out. The figure below shows a radioactive count fitted with an exponential model.

02040608010002004006008001000Time (s)CountsCountsy = 1000e-0.03002x, R2 = 1.0000
Counts fall from 1000 to 67 in 90 s. An exponential trendline gives a decay constant near 0.030 s⁻¹. Made with the Scatter Plot Maker.

Reading the decay example

The counts fall from 1000 to 67 over 90 seconds. Dividing ln(1000 / 67) = 2.70 by 90 gives a decay constant of roughly 0.030 s⁻¹, and the half-life is ln 2 / 0.030 ≈ 23 s. You can check this against the data: the count reaches about 500 between the 20 s reading (549) and the 30 s reading (407). The fitted curve gives you the same parameters with a measure of how well it matches.

Extrapolation and honest reporting

A fitted line describes the range of x you measured. Predicting outside that range assumes the relationship continues, which is often false: a linear dose response saturates, a growth curve levels off. Report the equation with sensible significant figures, give the R² and the number of points, and state the range over which the fit holds. If the points have uncertainty, show it with error bars.

Frequently asked questions

What is a good R² value?
It depends on the field. Analytical calibrations usually need 0.995 or higher; in biology or social science, values of 0.3 to 0.7 can still be meaningful. Judge it together with the residual plot.
Can R² be negative?
For an ordinary least-squares line with an intercept it cannot. It can be negative for a model forced through the origin or for a poorly chosen non-linear model, meaning the fit is worse than a horizontal line at the mean.
Should I force the line through the origin?
Only if physics requires y = 0 when x = 0 and you have checked the fit without the constraint. Forcing it can bias the slope and inflates R².
What is the difference between r and R²?
r is the correlation coefficient, between −1 and 1, and carries the sign of the slope. R² is its square for a linear fit, between 0 and 1, and is the fraction of variance explained.

Keep reading

Written and reviewed by the Plotiq Editorial Team. Spotted a mistake? Tell us and we will correct it. See About Plotiq for how these guides are made.