Method · Statistics Library

Scatter plot

A scatter plot draws each observation as a point with one variable on the x-axis and the other on the y-axis (above 5,000 rows KernelStats draws a seeded 5,000-point sample and says so on the card), the fundamental tool for visually exploring the relationship between two continuous variables before fitting any model.

Topic indexA reference reading outside the guided chapter sequence

Understand the idea

A scatter plot is the most direct way to see whether two numeric variables are related: plot one on each axis, and every row in your data becomes a single dot (for a table with more than 5,000 rows the card draws a representative 5,000-point sample and tells you so; the trend line and the numbers in the caption still use every row). Step back and look at the overall shape of the cloud of dots. A tight cloud rising from lower-left to upper-right means a strong positive relationship; a tight cloud falling from upper-left to lower-right means a strong negative one. A shapeless, scattered cloud with no visible slope suggests little to no LINEAR relationship (though a non-linear one could still be hiding in there).

Watch specifically for a CURVED pattern rather than a straight cloud: that tells you a relationship genuinely exists but a straight line is the wrong way to describe it, and a transformation or a curved model (polynomial, LOESS) is called for instead. Also watch for a handful of points sitting far away from the main cloud: these leverage points or outliers can single-handedly drag a straight-line fit toward themselves if you are not careful.

Adding a least-squares trend line gives a quick visual read on direction and rough strength, but it comes with an important caveat: if the underlying relationship is actually curved, that straight trend line will HIDE the curve rather than reveal it; always look at the raw scatter of points first, and treat the trend line as a summary, not a substitute for looking.

A scatter plot is the basic bivariate plot: it shows how two numeric variables move together.

Practitioner explanation

KernelStats plots via scattergl (WebGL-accelerated, appropriate for larger point counts) with a least-squares trend line (on by default, switchable off) (numpy polyfit degree 1), reporting the fitted equation, Pearson r, and R-squared directly in the caption when the trend line is drawn. Above 5,000 rows the drawn points are a deterministic (seeded) sample of 5,000 and the card's disclosure strip says so ('Plot shows a 5 000-point sample of N rows; statistics use all rows'); the trend line, Pearson r and R-squared are always computed from all rows. The trend line is silently skipped (with an explicit info-level warning, not a crash) when the x-variable is constant (zero variance), since a least-squares fit is undefined in that degenerate case.

This is a purely descriptive, exploratory visualization: no hypothesis test is run, and the reported Pearson r/R-squared are the SAME sample-level statistics Correlation Matrix or Linear Regression would compute, shown here as a quick visual companion rather than a substitute for either; a formal correlation test or regression with its own confidence intervals and assumption checks is the appropriate next step once the scatter suggests a relationship worth quantifying.

The product's own guidance names a specific reading discipline: use the scatter plot BEFORE fitting a regression, specifically to spot non-linear relationships, outliers, or distinct clusters/subpopulations that a regression's summary statistics alone (R-squared, a p-value) could easily hide; a strong correlation coefficient can coexist with a badly-fitting line if the relationship is actually curved or driven by a small cluster of points.

When to use it

Consider it when

You want to visually explore the relationship between two continuous variables, before fitting a regression, to spot non-linear patterns, outliers, or distinct clusters.

Use caution when

Either variable is categorical (use a bar chart, or a boxplot split by the category), or you already need a formal, inferential statement about the relationship (a correlation test or regression, with a confidence interval and assumption checks, rather than the descriptive trend line this plot shows).

Formulas and symbols

Least-squares trend line

y=β^1x+β^0y = \hat\beta_1 x + \hat\beta_0

Fitted by ordinary least squares (numpy polyfit, degree 1); skipped when x has zero variance.

Pearson correlation and R-squared

r=corr⁡(x,y),R2=1−SSresSStotr = \operatorname{corr}(x, y), \qquad R^2 = 1 - \dfrac{SS_{\text{res}}}{SS_{\text{tot}}}

Computed from the same trend-line fit; reported directly in the plot's caption.

Assumptions and checks

  • The card draws a least-squares trend line BY DEFAULT (trend = on); that line, and the r and R-squared in the caption, summarize a straight-line fit only, so reading linearity, a causal relationship, or a formal inference into the pattern goes beyond what the plot asserts.

    In KernelStats: Not applicable: this is a visualization, not a statistical test; use Correlation Matrix or a regression method for a fitted, quantified relationship.

Alternatives

  • Correlation Matrix. You want a formal correlation coefficient with a confidence interval and significance test, rather than a visual trend line.
  • Linear Regression. The scatter suggests a real relationship worth quantifying formally with a fitted equation, standard errors, and diagnostics.
  • Boxplot. One of the two variables is actually categorical rather than continuous.

Worked example

Scenario

A scatter plot of body mass against flipper length across 342 penguins, with a trend line.

Result

Pearson r = 0.87, R-squared = 0.76, trend line y = 49.7x - 5780; the cloud shows a clear upward trend with some visible spread by species.

Interpretation

The strong, tight upward cloud confirms a strong positive linear relationship worth quantifying formally, though the visible spread suggests checking whether species is a meaningful third variable (perhaps worth coloring the points by species) before treating the pooled trend line as the complete picture.

Dataset: penguins.csv

Common misconceptions

Misconception

A high R-squared on the trend line proves the relationship between the two variables is genuinely linear.

Correction

A trend line's R-squared measures how well a STRAIGHT LINE fits, but a curved relationship can still produce a deceptively high or misleadingly low R-squared depending on the data's range and spread. Always inspect the raw scatter for curvature, clusters, or outliers before trusting the trend line's summary: the line can hide exactly the pattern that matters most.

References

  1. NIST/SEMATECH e-Handbook of Statistical Methods, §1.3.3.26 Scatter plot, NIST/SEMATECH (2012), §1.3.3.26.