Seeing relationships
Scatter plots, overplotting and its fixes, trend lines, and why you must look before you summarize.
You will be able to
- Fix overplotting with transparency, binning or density
- Explain why a summary can't replace a scatter plot
- Scan many variables with a pair plot or heatmap
Read first
Look before you summarize
ReadThese datasets share nearly the same means, SDs and correlation. Move the slider from the cloud to each target and watch the summaries barely change as the picture does.
CExplorable · Same statistics, different pictures
How can datasets with identical summaries look nothing alike?
As the cloud morphs into this shape, what happens to Pearson's r?
Target
Mean, SD and correlation are held fixed along the way.
| Mean of x | SD of y | Pearson r | Spearman ρ |
|---|---|---|---|
| 54.30 | 26.90 | −0.060 | −0.029 |
Commit your prediction above to see the result
Make your prediction to see the result.
A correlation is one number. A scatter plot can show a curve, clusters, outliers or a shape no single number captures.
Too many points
PredictPredict first
A scatter plot has 100,000 points drawn at full opacity. What can you read about where most of the data sit?
Reveal
The answer: You can't tell where most points are
Very little. Points stack up, so one point and a thousand points look the same. This is overplottingOverplottingWhen points in a chart stack on top of each other, so one point and a thousand look the same and rare edges look as big as the core., and it makes the rare edges look as important as the dense core.
Fixes
ExploreCompare these on the same data in Charts, using Reshuffle demo to test a few datasets:
- Hexbin and 2-D histogram count points per cell.
- 2-D density contours smooth the counts.
- Large-n scatter (canvas) draws many points with transparency.
View data
| distance_km | fare_usd |
|---|---|
| 8.440 | 23.450 |
| 1.320 | 7.040 |
| 5.570 | 18.700 |
| 11.560 | 22.770 |
| 2.450 | 25.270 |
| 11.700 | 32.910 |
| 9.430 | 23.770 |
| 1.660 | 24.330 |
| 1.150 | 5.540 |
| 4.370 | 10.860 |
| 10.910 | 35.390 |
| 14.860 | 40.880 |
| 1.720 | 6.890 |
| 2.570 | 8.630 |
| 14.440 | 37.800 |
| 4.820 | 15.830 |
| 4.070 | 13.560 |
| 4.860 | 15.450 |
| 6.310 | 17.660 |
| 8.410 | 22.850 |
| 10.800 | 27.870 |
| 4.290 | 13.180 |
| 8.550 | 24.260 |
| 2.280 | 8.760 |
| 3.760 | 12.620 |
| 2.970 | 7.910 |
| 1.980 | 8.160 |
| 3.730 | 13.170 |
| 2.880 | 10.150 |
| 2.870 | 10.770 |
| 2.300 | 23.060 |
| 1.900 | 5.480 |
| 11.640 | 38.790 |
| 6.020 | 19.170 |
| 2.650 | 10.290 |
| 3.940 | 13.420 |
| 2.590 | 6.110 |
| 1.220 | 5.730 |
| 24.180 | 59.400 |
| 1.470 | 8.410 |
| 0.7300 | 4.800 |
| 4.060 | 11.880 |
| 3.700 | 15.360 |
| 4.540 | 12.090 |
| 4.320 | 14.910 |
| 2.300 | 9.720 |
| 7.340 | 15.490 |
| 2.720 | 25.790 |
| 3.530 | 10.230 |
| 5.530 | 16.560 |
| 13.370 | 29.550 |
| 5.410 | 18.700 |
| 0.6600 | 4.600 |
| 3.240 | 10.810 |
| 8.890 | 24.690 |
| 3.060 | 24.520 |
| 4.480 | 12.320 |
| 24.340 | 56.300 |
| 6.760 | 21.700 |
| 8.350 | 25.130 |
First 60 of 5000 rows.
Binned charts lose individual outliers. To see those too, show them on top.
Trends and margins
ReadA trend line helps the eye, but a straight line says "the relationship is straight", whether or not it is. Try a smoother, and look at the residuals.
Scatter with marginals adds each variable's distribution along its axis, so you can see skew and gaps next to the relationship.
View data
| bill_length_mm | flipper_length_mm | species |
|---|---|---|
| 37.200 | 203 | Adelie |
| 44.300 | 188 | Adelie |
| 45.600 | 193 | Adelie |
| 39.700 | 196 | Adelie |
| 41.600 | 192 | Adelie |
| 36.400 | 187 | Adelie |
| 35.700 | 191 | Adelie |
| 37.800 | 204 | Adelie |
| 35.700 | 183 | Adelie |
| 40.100 | 187 | Adelie |
| 42.800 | 196 | Adelie |
| 39.100 | 194 | Adelie |
| 37.700 | 185 | Adelie |
| 32.100 | 183 | Adelie |
| 39.600 | 182 | Adelie |
| 40.900 | 190 | Adelie |
| 42.400 | 193 | Adelie |
| 35.300 | 190 | Adelie |
| 36.600 | 193 | Adelie |
| 43.400 | 190 | Adelie |
| 38.400 | 182 | Adelie |
| 43.300 | 201 | Adelie |
| 42.500 | 204 | Adelie |
| 38.200 | 198 | Adelie |
| 42.900 | 200 | Adelie |
| 46.200 | 189 | Adelie |
| 35.200 | 197 | Adelie |
| 43.100 | 190 | Adelie |
| 36 | 189 | Adelie |
| 38.900 | 194 | Adelie |
| 36.700 | 196 | Adelie |
| 34.900 | 184 | Adelie |
| 37.900 | 190 | Adelie |
| 36.300 | 175 | Adelie |
| 35.400 | 191 | Adelie |
| 39.300 | 204 | Adelie |
| 38 | 185 | Adelie |
| 40.900 | 201 | Adelie |
| 35.200 | 179 | Adelie |
| 39.200 | 185 | Adelie |
| 39 | 185 | Adelie |
| 35.500 | 186 | Adelie |
| 36.400 | 191 | Adelie |
| 45.900 | 194 | Adelie |
| 35.600 | 191 | Adelie |
| 37.500 | 187 | Adelie |
| 43 | 206 | Adelie |
| 40.400 | 193 | Adelie |
| 39.600 | 180 | Adelie |
| 41.100 | 196 | Adelie |
| 35.900 | 179 | Adelie |
| 33.700 | 173 | Adelie |
| 38.700 | 189 | Adelie |
| 36.800 | 184 | Adelie |
| 31.900 | 183 | Adelie |
| 38.100 | 191 | Adelie |
| 37.100 | 184 | Adelie |
| 38.900 | 189 | Adelie |
| 36.500 | 192 | Adelie |
| 39.100 | 197 | Adelie |
First 60 of 333 rows.
Many variables at once
In the appA Pair plot draws every pair. A Correlation heatmap shrinks that to color. Use the heatmap to find pairs worth plotting, then plot them, since the heatmap can't show a curve.
Open the Correlation heatmap with Use my data on a table of yours. Pick the strongest pair and draw its scatter.
View data
| income_k | monthly_spend | tenure_months | site_visits | churn_risk | support_tickets | age |
|---|---|---|---|---|---|---|
| 80.930 | 780.26 | 34.080 | 34.850 | 0.1800 | 2.280 | 32.190 |
| 47.270 | 461.25 | 19.960 | 17.330 | 0.4100 | 1.200 | 34.480 |
| 95 | 521.32 | 44.610 | 24.300 | 0.3800 | 2.800 | 52.640 |
| 95.540 | 586.09 | 15.320 | 18.070 | 0.5800 | 4.390 | 43.750 |
| 50.310 | 543.21 | 29.970 | 17.490 | 0.3400 | 1.440 | 50.340 |
| 91.180 | 674.85 | 17.870 | 25.270 | 0.3500 | 2.700 | 29.910 |
| 81.700 | 545.98 | 27.180 | 14.020 | 0.3500 | 2.730 | 42.510 |
| 29.490 | 319.70 | 5.160 | 7.700 | 0.5500 | 3.700 | 56.400 |
| 19.100 | 314.19 | 25.930 | 16.930 | 0.2700 | 5.980 | 33.040 |
| 57.250 | 511.94 | 33.100 | 29.030 | 0.4000 | 3.730 | 41.990 |
| 86.670 | 567.01 | 35.290 | 28.640 | 0.3900 | 0.8000 | 59.170 |
| 87.070 | 735.23 | −9.260 | 14.690 | 0.6200 | 5.700 | 47.630 |
| 37.850 | 213.54 | 9.190 | 20.300 | 0.4700 | 5.970 | 49.180 |
| 47.320 | 422.69 | 16.830 | 22.810 | 0.3400 | 3.500 | 49.840 |
| 97.670 | 830.04 | 28.340 | 22.530 | 0.2200 | 2.860 | 36.090 |
| 54.480 | 409.62 | 29.570 | 19.060 | 0.4900 | 2.180 | 45.740 |
| 61.230 | 654.44 | 52.780 | 26.110 | 0.2400 | 2.380 | 44.130 |
| 76.080 | 648.17 | 46.350 | 22.400 | 0.2500 | 3.620 | 40.060 |
| 64.910 | 570.33 | 29.690 | 14.860 | 0.4300 | 3.400 | 47.290 |
| 80.450 | 539.32 | 27.720 | 19.440 | 0.1600 | 2.750 | 35.610 |
| 102.86 | 741.77 | 48.440 | 21.550 | 0.1600 | 2.360 | 78.900 |
| 69.970 | 369.25 | 25.410 | 12.550 | 0.4500 | 3.750 | 55.480 |
| 95.010 | 552.42 | 10.850 | 19.570 | 0.4100 | 6.200 | 30.310 |
| 63.690 | 461.60 | 21.750 | 21.880 | 0.3400 | 3.050 | 55.910 |
| 60.500 | 494.68 | 18.400 | 25.990 | 0.5000 | 0.6400 | 38.830 |
| 46.610 | 601.94 | 29.410 | 16.150 | 0.3300 | 1.850 | 45.970 |
| 44.760 | 429.08 | 46.500 | 17.070 | 0.3000 | 5.140 | 39.360 |
| 70.490 | 464.49 | 27.080 | 18.590 | 0.4100 | 5.130 | 60.150 |
| 54.720 | 275.77 | 29.100 | 16.090 | 0.4100 | 6.750 | 47.780 |
| 61.250 | 438.57 | 15.270 | 11.210 | 0.4600 | 4.300 | 36.610 |
| 48.210 | 512.93 | 49.550 | 20.800 | 0.3400 | 3.180 | 35.480 |
| 32.800 | 449.18 | 23.480 | 15.060 | 0.5100 | 4.040 | 41.050 |
| 89.020 | 550.96 | 4.940 | 15.400 | 0.4900 | 5.390 | 31.200 |
| 74.990 | 574.93 | 26.600 | 16.990 | 0.4500 | 2.100 | 35.990 |
| 67.050 | 448.28 | 45.510 | 22.460 | 0.3500 | 3.540 | 53.600 |
| 78.700 | 622.64 | −3.800 | 23.020 | 0.5400 | 5.720 | 35.440 |
| 45.410 | 477.03 | 7.730 | 18.790 | 0.4400 | 3.200 | 29.950 |
| 39.300 | 520.85 | 52.960 | 18.230 | 0.3700 | 1.360 | 26.920 |
| 123.55 | 813.55 | 34.430 | 32.130 | 0.0900 | 2.440 | 37.210 |
| 43.770 | 395.35 | 28.420 | 21.160 | 0.3200 | 3.140 | 58.220 |
| 22.950 | 254.42 | 16.850 | 12.240 | 0.4700 | 5.190 | 22.720 |
| 57.680 | 491.68 | 9.910 | 21.690 | 0.4300 | 5.470 | 43.110 |
| 55.730 | 593.49 | 15.800 | 16.220 | 0.4700 | 3.260 | 45.730 |
| 51.720 | 511.79 | 40.130 | 21.930 | 0.2100 | 4.820 | 26.720 |
| 64.070 | 466.48 | 11.580 | 9.530 | 0.6600 | 4.040 | 14.300 |
| 33.160 | 476.96 | 33.250 | 12.060 | 0.5100 | 3.790 | 46.760 |
| 66.850 | 688.54 | 61.860 | 25.590 | 0.2700 | 1.740 | 56.240 |
| 55.790 | 509.98 | 55.800 | 21.430 | 0.2400 | 2.690 | 42.950 |
| 54.110 | 532.32 | 28.600 | 22.450 | 0.5400 | 3.960 | 33.850 |
| 79.290 | 587.20 | 48.120 | 26.570 | 0.1000 | 1.370 | 33.010 |
| 95.640 | 772.62 | 23.150 | 25.710 | 0.3400 | 1.130 | 56.280 |
| 71.930 | 524.45 | 12.020 | 17.830 | 0.4500 | 2.240 | 47.710 |
| 17.270 | 158.84 | 38.320 | 20.460 | 0.2300 | 3.950 | 57.810 |
| 70.720 | 445.36 | 29.120 | 18.040 | 0.2000 | 1.800 | 39.940 |
| 91.290 | 563.83 | −6.960 | 13.740 | 0.6400 | 4.550 | 19.740 |
| 62.140 | 422.81 | 27.230 | 12.530 | 0.3400 | 5.570 | 38.320 |
| 52.110 | 505.46 | 18.110 | 17.260 | 0.4400 | 4.090 | 45.020 |
| 94.160 | 754.58 | 13.850 | 21.320 | 0.3400 | 4.510 | 34.180 |
| 68.950 | 609.48 | 51.990 | 17.960 | 0.2100 | 2.840 | 30.840 |
| 100.43 | 653 | 32.330 | 13.450 | 0.3800 | 2.780 | 60.990 |
First 60 of 400 rows.
Check your understanding
CheckpointCheck yourself
You have 2 million rows. Which is a good way to see a relationship?
Show the answer
Answer: a
Counting per cell shows where the mass is. Larger points make overplotting worse.
Check yourself
Two scatter plots have identical correlation, means and SDs. What must be true?
Show the answer
Answer: c
That's the point of Anscombe's quartet and the Datasaurus. Summaries don't determine the picture.
Recap
Recap- A summary can't stand in for a scatter plot.
- With many points, bin or smooth to see the mass.
- Scan with a heatmap, then look at the pairs that matter.
Concepts in this lesson