## How to add reference line y=x to scatter plot

Occasional Contributor
Posts: 11

# How to add reference line y=x to scatter plot

How can I add the y=x line to my scatter plots?
Thanks
Regular Contributor
Posts: 165

## Re: How to add reference line y=x to scatter plot

Is this for proc gplot? I think the simplest way is to use the overlay option and plot one variable against itself.

proc gplot data=dataset;
plot y*x x*x/overlay;
run;

You could also create another dummy variable that spans the x/y axis in case there isn't enough variability in x or y.

Using an annotated dataset would also work.
Occasional Contributor
Posts: 11

## Re: How to add reference line y=x to scatter plot

Thanks. I just meant is there a way to plot a reference line with 0 intercept and slope = 1.
Occasional Contributor
Posts: 11

## Re: How to add reference line y=x to scatter plot

I am trying to make agreement plots without using the Ttest procedure in GPLOT or SGPLOT.
Regular Contributor
Posts: 165

## Re: How to add reference line y=x to scatter plot

Right, plotting any variable against itself is a line with an intercept at 0 and slope of 1 (x=1*x+0). SAS has options to add vertical or horizontal reference lines (x=5 or y=10) but not for x=y. That it why you would need to either plot another line (x*x or y*y) or use the annotation facility to draw a line on top of the graph.
Occasional Contributor
Posts: 11

## Re: How to add reference line y=x to scatter plot

Doh! Thank you very much!
Valued Guide
Posts: 765

## Re: How to add reference line y=x to scatter plot

* some fake data;
data x;
do x = 1 to 10;
y = 6 + ceil(10*ranuni(999));
output;
end;
run;

goptions reset=all;

symbol1 v=dot c=blue;
symbol2 i=join c=blue ;

proc gplot data=x;
plot (y x)*x / overlay;
run;
quit;

also, using annotate is actually a bit harder in that the above method does not require you to have any knowledge as to how SAS/Graph will choose the ranges of the x and y axes

if you use annotate, then only safe way to add the line is to control the axis ranges with AXIS statements that specify ORDER and then use that axis range info to specify end points of a line drawn with annotate
Discussion stats
• 6 replies
• 4844 views
• 0 likes
• 3 in conversation