How to use the scatter plot maker
- Type or paste your x and y pairs, one pair per line, separated by a comma, tab or space. A first line of words is used as the axis names. Press Use example data to see a sample.
- Add a title and labels for the axes if you like. Keep Show the fitted line ticked to draw the least squares line, or untick it for the points alone.
- The chart and the numbers appear as you type: the number of points, the equation of the line, the correlation r and R squared.
- Use Download PNG or Download SVG for the picture, or Copy results for the numbers.
Formula
slope = sum of (x - mean x)(y - mean y) / sum of (x - mean x)^2
intercept = mean y - slope x mean x
r = sum of (x - mean x)(y - mean y) / sqrt(sum of (x - mean x)^2 x sum of (y - mean y)^2)
R squared = r^2
The line is the ordinary least squares fit, which minimizes the sum of the squared vertical distances from the points to the line. r is the Pearson correlation and lies between -1 and 1.
Points on a straight line
The points (1, 2), (2, 4), (3, 6) and (4, 8) all lie on the line y = 2x. The tool reports a slope of 2, an intercept of 0 and a correlation r of 1, so R squared is 1. The fitted line passes through every point.
A noisier set of 20 points drawn around y = 2.5x + 4 gives a fitted line of y = 2.51707x + 2.83582, with r = 0.946001 and R squared = 0.894918. That means about 89% of the variation in y is accounted for by a straight line in x. These figures match numpy.
Reading the line and r
The slope says how much y changes, on average, for each one unit increase in x. The intercept is where the line meets x = 0, which may be outside your data and then has no practical meaning. The correlation r says how closely the points follow a straight line: near 1 means a tight upward trend, near -1 a tight downward trend and near 0 no straight line trend.
R squared is the share of the variation in y that the line accounts for. A high value does not mean x causes y, and a low value does not mean there is no relationship, because a curve can have a low r. Always look at the picture as well as the numbers. For the numbers alone, see the linear regression calculator.
Making a clear plot
Label both axes with what is measured and its unit. Keep the title short and plain. If one point sits far from the others, check that it is not a typing error before you draw conclusions, because a single outlier can pull the fitted line a long way.
The chart uses colors that stay distinct for color blind readers, and the PNG is drawn at twice the on-screen size for sharp printing. Other charts are in the chart maker, and for the shape of a single list of numbers, the histogram maker.
Privacy and limits
Everything is drawn in your browser and nothing is uploaded. Up to 5,000 points fit. A line needs at least two points with different x values.
Assumptions and limits
- The line is fitted by ordinary least squares, treating y as the value predicted from x.
- Numbers use a period for decimals and no thousands separators.
- A first line that is not numbers is read as the names of the axes.
- The picture and the numbers are descriptions of the data you enter, and correlation does not show cause.
Frequently asked questions
What does R squared mean?
It is the share of the variation in y that the fitted straight line accounts for, from 0 to 1. A value of 0.89 means the line explains about 89% of the variation.
Why is r not defined for my data?
When every y value is the same, the points form a flat line and there is no variation to correlate, so r and R squared are not defined. The slope is 0.
Why can no line be fitted?
If every x value is the same the points stand in a vertical column, and a line of the form y = mx + b cannot pass through them. Check that the x values differ.
Can I plot more than one series?
This tool plots one set of x and y pairs. To compare several series, make a separate plot for each, or try the chart maker for line and bar charts.