# Tool to draw normal QQ-plot with 45 degree reference line

I have some data (a set of numbers) and I want to compare them with the normal distribution using QQ-plot. The only statistical tool that I am aware of is Octave but Octave doesn't draw the reference line.

As can be seen in the above picture the x-axis has a range from - 3 to 3 but the y-axis has a range from 20 to 140. I think drawing a 45 degree slope line would be wrong.

How can I draw such a reference line in Octave? Or does there exist any easy tool that would draw a QQ-plot with that reference line?

This is easy in R:

x <- rnorm(1000, 100, 10)  #Creates some data; this has is normal with mean 100 sd 10
qqnorm(x)         #qq

• Thanks alot :) , .. in one of my number sets the reference line was horizontal is that ok ? – Ahmed Kotb Mar 18 '12 at 20:07
• I think that's a problem – Peter Flom Mar 18 '12 at 20:08
• a problem in the integers (that they don't follow the normal dist) OR a problem in drawing them ? – Ahmed Kotb Mar 18 '12 at 20:23
• It's OK that they aren't normal (that's part of the reason to use a qq plot). A horizontal line though.... what are your data? – Peter Flom Mar 18 '12 at 20:39
• just a bunch of numbers that are very close to each other dl.dropbox.com/u/8045913/faculty_stuff/tcp_wired_lan_client.txt – Ahmed Kotb Mar 18 '12 at 20:46

Here is one possible Octave solution to your question: (largely inspired from the corresponding Matlab function)

randn("state",255)
x = normrnd(10, 2, 200, 1);
[q, s] = qqplot(x);

% compute the y=x line
dx = prctile(q, 75) - prctile(q, 25);
dy = prctile(s, 75) - prctile(s, 25);
b = dy./dx;                                % slope
xc = (prctile(q, 25) + prctile(q, 75))/2;  % center points
yc = (prctile(s, 25) + prctile(s, 75))/2;  % ...
ymax = yc + b.*(max(q)-xc);
ymin = yc - b.*(xc-min(q));

plot(q, s, "Linestyle", "none", "Marker", "+")
line([min(q); max(q)], [ymin; ymax])