Scatterplot: how to plot and read the relation of two variables

Updated

A scatterplot plots pairs of measurements as points: one variable on the horizontal axis, the other on the vertical axis, one point per row of data. It is the basic picture of a relationship. In a few seconds it shows whether the two variables move together, how tightly, whether the pattern is straight or curved, and whether any points break the pattern.

When to use it

  • You suspect that a process input drives an output: temperature and hardness, feed rate and roughness, humidity and adhesion.
  • You want to check a relationship before you compute a correlation or fit a regression, since both summarize a pattern that may not be there.
  • You compare two measurements of the same parts, such as an in-line gauge against the lab.
  • You look for groups or outliers that only appear when two variables are viewed together.

How it works

  1. Put the variable you control or suspect is the cause (X) on the horizontal axis and the result (Y) on the vertical axis.
  2. Draw one point per row at (x, y).
  3. Optionally add a least-squares line, ŷ = b₀ + b₁x, which minimizes the sum of squared vertical distances from the points to the line.
  4. Optionally mark groups (machine, shift, lot) with different symbols or colors.

The Pearson correlation r summarizes how close the points lie to a straight line, from −1 to +1:

r = Σ (xᵢ − x̄)(yᵢ − ȳ) / √( Σ (xᵢ − x̄)² × Σ (yᵢ − ȳ)² )

r² is the share of the variation in Y that the straight line accounts for. Both are only meaningful when the picture shows a roughly straight pattern without extreme points.

Example

A machine shop finishes steel shafts on a CNC lathe. The drawing allows a surface roughness of at most Ra 1.6 µm. To choose the finishing feed, a programmer turns two shafts at each of eight feed rates and measures Ra:

Feed (mm/rev)0.100.120.140.160.180.200.220.24
Ra, shaft 1 (µm)1.071.531.311.621.682.082.272.23
Ra, shaft 2 (µm)1.131.411.511.711.902.242.292.68
Scatterplot of roughness versus feed rate1.01.52.02.5Ra (µm)0.100.150.20Feed (mm/rev)
Scatterplot of roughness versus feed rate

The points rise steadily from left to right with a modest scatter around the line. The numbers agree with the picture:

  • Correlation r = 0.957, so r² = 0.917: the straight line accounts for about 92% of the variation in roughness over this range.
  • Least-squares line: Ra = 0.181 + 9.470 × feed. Each extra 0.01 mm/rev of feed adds about 0.095 µm of roughness.
  • The points scatter around the line with a standard deviation of 0.140 µm.

The line reaches 1.6 µm at a feed of 0.150 mm/rev. That feed would put the average shaft right at the limit, so about half the shafts would fail. At 0.12 mm/rev the line predicts 1.32 µm, two residual standard deviations below the limit, which is a safer choice. Note that one shaft at 0.12 already read 1.53 µm: individual parts vary around the line, and the margin has to cover that.

Machining theory says roughness grows with the square of the feed, so the true curve bends upward. Over this narrow range a straight line is a fair approximation, but it should not be extended to feeds outside 0.10 to 0.24 mm/rev.

How to read the results

  • Direction. Points rising to the right mean a positive relationship; falling, a negative one.
  • Strength. A narrow band means a strong relationship; a round cloud means little or none.
  • Form. Look for curves, plateaus or thresholds. A straight line and r describe only straight patterns.
  • Spread along X. A fan that widens as X grows means the variation depends on X, which matters for predictions.
  • Unusual points. A point far from the pattern, especially at an extreme X, can change the line and r a great deal on its own.
  • Groups. Two separate clouds, for example one per machine, can create a correlation that exists within neither group. Mark the groups and look again.

Common mistakes

  • Equating correlation with cause. Here the feed was set deliberately, so a causal reading is reasonable. With data collected as it came, a third variable such as tool wear or material lot may drive both.
  • Extrapolating the line. The fit only describes the range you tested.
  • Trusting r without the plot. Very different pictures, including a curve or one extreme point, can share the same r.
  • Overplotting. With thousands of rows, points pile up and hide the density. Use a binned scatterplot or transparency.
  • Swapping the axes for a fit. Regressing Y on X is not the same as X on Y. Put the response on the vertical axis.

Frequently asked questions

What does a scatterplot show?

The relationship between two numeric variables measured on the same items: direction, strength, form, and unusual points.

What is a good correlation value?

It depends on the purpose. For a calibration check you may need r above 0.99; for a process input among several, r = 0.5 can matter. Always look at the plot, and test whether r differs from zero with the correlation analysis.

How do I plot more than two variables?

Use a matrix plot for every pair at once, a bubble plot to add a third variable as point size, or different symbols for a grouping variable.

What is the difference between a scatterplot and a fitted line plot?

A scatterplot shows the points, optionally with a simple line. A fitted line plot is part of a regression analysis: it shows the fitted equation, R², and can add confidence and prediction bands and curved (quadratic or cubic) fits.

Try it with your own data

StatLab SPC is free, open-source statistics for engineers. It runs in your browser, works offline, and never uploads your data.

Open StatLab