Best-fit line: scatter plot, correlation r and residuals

Choose a made-up data set, draw your own line through the dots and compare it with the least-squares best-fit line. See r, r squared and the gaps (residuals) that the best-fit line makes as small as possible.

Keep it one tap away for everyday use.

Bookmark Best-fit line?

Press Ctrl + D now. Your browser opens its own bookmark box, where you choose the name and folder.

Or install fibub as an app: every tool you open then works offline.

  1. Add dots
  2. Your line
  3. Best fit
  4. Quiz
Nothing is uploadedWorks offline once open

Each dot is one person or day. Choose a set of made-up data, then set your own line and see how close you get to the best-fit line. Tap or click the graph to add your own dot.

Try this

  • Move your line until the "your line" total is as small as you can get it. How close can you get to the best-fit total?
  • Switch to "Shoe size and score": r is near 0, so a line explains almost nothing.
  • Add one dot far above the others. How much does the best-fit line move?

Check yourself

What it does

A scatter plot puts one measurement on each axis, so every dot is one person, day or object. If the dots drift upward together, the two things move together. A line of best fit sums up that trend in one equation, and it lets you predict a value you did not measure. This page gives you three made-up data sets, a line you can set yourself with two sliders, and the real least-squares line to compare with.

The least-squares line is the one that makes the total of the squared gaps (the residuals) between the dots and the line as small as possible. The number r measures how tightly the dots follow a straight line, from −1 to +1. After this, try histogram builder for single sets of numbers or regression workbench for your own data.

How to use it

  1. Pick a data set: study time and score, heat and cold drinks, or shoe size and score.
  2. Move the slope and intercept sliders until your orange dashed line runs through the middle of the dots.
  3. Press “Show best-fit line”. The green line and the little vertical gaps appear.
  4. Compare the two totals under the graph. Smaller means closer.
  5. Tap the graph to add your own dot and see how r and the line change.

What each setting does

  • Your slope: how steeply your line rises for each step right.
  • Your intercept: where your line crosses the vertical axis at x = 0.
  • Show best-fit line: adds the least-squares line and its residuals.
  • Reset dots: removes the dots you added.

Worked example

Take the five points (1, 2), (2, 4), (3, 5), (4, 4) and (5, 5). The means are 3 and 4. The best-fit line is y = 0.6x + 2.2 and r is about 0.77, a fairly strong positive link. At x = 6 the line predicts 5.8.

FAQs

Does a high r prove one thing causes the other? No. Hot weather and cold drink sales move together, but a link in data never proves cause on its own.

Why squared gaps? Squaring stops positive and negative gaps from cancelling and makes big misses count more.

Can I use the line far outside the data? Be careful. Predicting well beyond the dots (extrapolating) can go badly wrong.

Where the numbers come from

  • Scatter plots, lines of best fit, residuals and the correlation coefficient are standard school statistics (Common Core 8.SP and HS-S-ID.6 to 9). The least-squares formulas are checked on hand-worked data in tests/sci.mjs. All three data sets are made up by fibub for teaching.

Standard scientific values, such as constants, atomic weights and melting points, are facts found in every textbook; we name where ours were checked. If you are an author or publisher and want a value, a credit or a table changed or removed, tell us and we will act quickly.

Last updated 2026-11-16.

Change log for Best-fit line

  1. Learn: USA curriculum pages, guides, tests and share images for 8 new tools Details on GitHub
  2. Learn: USA grade 8-12 curriculum map and 8 new tools (Common Core, NGSS) Details on GitHub

Every change to fibub

Related tools

Regression workbench #T389 Paste a table or open a CSV or Excel file and fit a multiple linear, polynomial or logistic regression. Get coefficients with standard errors, t or z tests, p-values and confidence intervals, R², adjusted R², AIC and BIC, odds ratios, predictions with intervals, and the diagnostic plots: residuals, Q-Q, leverage and Cook's distance, with VIF. Matches statsmodels. Linear function explorer #L154 Slide m and c, or drag the line itself, and see y = mx + c drawn with its slope triangle (rise over run), the point where it cuts the y-axis and the zero where it meets the x-axis, all worked with your numbers. A Class 11 level adds the angle of the line and its other forms. Histogram builder #L167 Type a list of numbers and drag the class width and starting point to watch the frequency table, the histogram and the frequency polygon change. See the mean, median, mode and modal class, how far the mean from the table drifts from the true mean, and the combined mean of two groups. Quadratic explorer #L68 Slide a, b and c and watch the parabola move: vertex, roots and the discriminant update live, completing the square is drawn with tiles, and the middle term is split for you. With fresh practice questions. Pythagoras proof playground #L69 Drag a right triangle and watch the squares on its sides add up. Slide through four visual proofs (rearrangement, Bhaskara, similar triangles, Baudhayana) with your own side lengths, and list Pythagorean triples. Trig ratio explorer #L70 Drag the angle of a right triangle and see sin, cos and tan as ratios of its sides, with the exact values at 0°, 30°, 45°, 60° and 90°, the identities checked live, and the full unit circle for Class 11.