How to Add a Trendline, Equation and R² in Excel
A trendline with its equation and R² takes a few clicks in desktop Excel, but picking the right type and reading the result takes more care. This guide covers both ways to get the numbers, the cell formulas that give the same answers, and how to choose a model without fooling yourself.
Method 1: add the trendline to the chart
Start with a scatter chart of your data (see the scatter plot guide). In desktop Excel, click one data point so the whole series is selected, then click the plus icon next to the chart and tick Trendline. Excel adds a linear trendline by default. Right-click the line and choose Format Trendline to open the options pane.
In that pane pick the type (Linear, Exponential, Logarithmic, Polynomial, Power or Moving Average), then tick Display Equation on chart and Display R-squared value on chart. The equation appears as a text box on the chart. Drag it somewhere clear of the points, and right-click it → Format Trendline Label → Number to show more digits, because Excel often rounds the slope so heavily that the equation is useless for calculation.
Excel for the web has a smaller set of chart options than the desktop app and they change over time. If the Trendline or equation options are missing there, use the formulas below or open the workbook in desktop Excel.
Method 2: get the same numbers from cell formulas
You do not need a chart to get the regression numbers, and formulas give you full precision. With the X values in A2:A8 and the Y values in B2:B8: =SLOPE(B2:B8, A2:A8) returns the slope, =INTERCEPT(B2:B8, A2:A8) the intercept and =RSQ(B2:B8, A2:A8) the R². Note the order: the Y range comes first, then the X range. Reversing them silently gives the regression of X on Y, which is a different line.
For more detail use =LINEST(B2:B8, A2:A8, TRUE, TRUE). It returns the slope and intercept together with their standard errors, R², the standard error of the estimate and the degrees of freedom, which you need for confidence intervals and for the detection limit of a calibration. In older versions of Excel it must be entered as an array formula with Ctrl+Shift+Enter.
For exponential and power models, Excel fits the line to the logarithm of Y (and X for power). Use =LOGEST() for an exponential fit, or take LN of the values yourself and use SLOPE and INTERCEPT on the logged columns. The semi-log and log-log pages explain what the transformed slope means.
Which trendline type should you choose?
Choose from what you know about the process, not from whichever curve has the highest R². Linear is for proportional relationships and calibrations. Exponential is for growth or decay at a constant percentage rate and cannot handle zero or negative Y. Logarithmic is for values that rise quickly and then level off, and needs positive X. Power is for scaling laws and needs positive X and Y. Polynomial adds a bend or two; use order 2 or 3 only to describe a smooth curve, never to predict outside the data.
The figure below shows why R² cannot decide. A second-order polynomial fits the decay data very closely, with an R² of about 0.994, but physically the process is exponential. The fitted parabola reaches its lowest point near 80 seconds and then curves back upward, predicting counts that rise again. A higher R² from a more flexible model is expected and does not mean a better model.
Reading the equation and R² correctly
For a linear fit y = mx + b the slope m is the change in y per unit x, and the intercept b is the value of y when x is zero. R² is the fraction of the variation in y that the line explains: 0.98 means 98% of the variation is accounted for and 2% is left over as scatter. It says nothing about whether the relationship is causal, whether a curve would suit better, or how large the errors are in your units.
Always look at the chart and the residuals as well. A curved pattern in the residuals means the line is the wrong shape, however high R² is. The longer guide to line of best fit and R² covers Anscombe’s quartet, residual plots and extrapolation.
Doing it without Excel
If you only have a CSV, or you want a figure ready for a report, the same fits are available in the browser. Paste or open the data in the scatter plot maker, choose the trendline type, and the equation and R² appear in the legend and in a results table below the chart. There is nothing to install and the data stays on your device. You can then export the figure as SVG, PDF or PNG, with sizes that match a journal column.
Google Sheets can also do it: in the chart editor choose Customize → Series, tick Trendline, and set the label to “Use equation” and tick “Show R²”.
Frequently asked questions
- How do I show the R² value on an Excel chart?
- Right-click the trendline, choose Format Trendline, and tick “Display R-squared value on chart”. The R² appears beside the equation.
- Why is my Excel trendline equation so rounded?
- Excel shortens the label by default. Right-click the equation label, choose Format Trendline Label → Number and increase the decimal places, or use SLOPE and INTERCEPT in cells for full precision.
- What is the difference between RSQ and the R² on the chart?
- For a linear trendline they are identical. For exponential and power trendlines the chart R² is calculated on the transformed (logarithmic) values.
- Can I add a trendline in Excel Online?
- Chart options in Excel for the web are more limited than in the desktop app and vary by release. If the option is not there, calculate with SLOPE, INTERCEPT and RSQ, or open the file in desktop Excel.
- How do I calculate the line of best fit by hand?
- The slope is the sum of (x − mean x)(y − mean y) divided by the sum of (x − mean x)², and the intercept is mean y minus the slope times mean x.
Keep reading
- How to Make a Scatter Plot in Excel Online – Step-by-step scatter plot in Excel for the web and desktop Excel, how to set the axes correctly, what the web version cannot do, and a free alternative for a CSV.
- Line of Best Fit and R²: What They Really Tell You – How least-squares finds a line of best fit, what R² does and does not tell you, how to read residuals and when to use a curve.
- How to Make a Calibration Curve – Step-by-step calibration curve: plot standards, fit a line, check R² and residuals, then calculate an unknown concentration, LOD and LOQ from real numbers.
Written by Dev Patel. Spotted a mistake? Tell me and I will correct it. See About Plotiq for how these guides are made.