# how to create scatter of points?

I am going to teach econometrics soon and as some of you might know, there is this concept of regression where we try to fit a a best plot on the data.

I know how to make a graph with just one point (as shown below). But is there a simpler way to plot some random points around a straight line?

Basically I would like to create a scatterplot such that the points are random on the graph but not too much. In other words points are on a line but say there is a random error in $y$. Also, can I control the variance of this error with values of $x$?

\documentclass{article}
\usepackage{tikz}
\begin{document}
\begin{tikzpicture}[xscale=3, yscale=1.5]
\draw [thick, <->] (0,1) -- (0,0) -- (1,0);
\node [below right] at (1,0) {$x$};
14
\node [left] at (0,1) {$y$};

• @Jake: Thanks very much for the useful link. I have an even extended version of the question. How to make the points scatter even more at some part keeping the line same (case 1) and for two different lines (case 2). Or in other words say in the example in the linked question, how to make the dots after weight 80 more away' from the line? – Abhimanyu Arora Jun 6 '14 at 11:15
• @AbhimanyuArora: In that example, you could use create on use/y/.style={create col/expr={(0.6*\thisrow{x}+130)+(\thisrow{x}<80?3:10)*rand}}. The key part there is the expression (\thisrow{x}<80?3:10)*rand`, which means "If x is less than 80, use a spread of 3, else use a spread of 10". – Jake Jun 6 '14 at 11:27