Data visualization with SAS programming

adding an equation to draw to a plot statement

Reply
N/A
Posts: 0

adding an equation to draw to a plot statement

Hello dears sas users
My problem is the following:
imagine that i have a plot to draw and i want also to add in the graphic an equation
like Y=X
is it possible ?
because for the moment, i work like that but if there is a shorter and easier way to do it, it would be nice
here is my code:

data class;
set sashelp.class end=fin;
x_1= _n_ * 3;
y_1= _n_ * 3;
weight=weight/2;
if _n_ = 1 then do;; x_1=0; y_1=0; end;
if fin then do; x_1=80; y_1=80; end;
run;

goptions reset=all;
title 'is there a shorter way ???';

symbol1 color=red
interpol=join
value=dot
height=3;

symbol2 value=none
color=black
interpol=join
height=2;

axis1 order=(0 to 100 by 20) offset=(0,0)
label=none
major=(height=2) minor=(height=1)
width=3;

axis2 order=(0 to 100 by 20) offset=(0,0)
label=none
major=(height=2) minor=(height=1)
width=3;

proc gplot data=class;
plot height*weight x_1*y_1 / overlay haxis=axis1 vaxis=axis2 ;
run;
quit;

may be is a dream but it would be very nice if the following code exists;

proc gplot data=sashelp.class;
plot height*weight;
equation Y=X; (this isn't exist yet)
run;
quit;

Thank you very much for yours answers.
PROC Star
Posts: 1,672

Re: adding an equation to draw to a plot statement

The alternative is to use annotation, but that's not simpler.

This allows to manage the 2 plots' data separately:

data class;
set sashelp.class;
weight=weight/2;
output;
if _n_ = 1 then do;
do x_1=0 to 100 by 5;
y_1=x_1**1.2 - 1.5*x - 5 ;
output;
end;
end;
run;
SAS Employee
Posts: 980

Re: adding an equation to draw to a plot statement

If you're doing a regression like, you can use the 'regeqn' gplot option, such as:

symbol1 interpol=rcclm95 value=circle cv=red ci=pink co=blue;
proc gplot data=sashelp.class;
plot height*weight=1 / regeqn;
run;

-----

Otherwise, you can use the 'note' option to print some text (equation) such as:

symbol v=dot i=none;
proc gplot data=sashelp.class;
plot height*weight;
note move=(20,80)pct c=blue height=3.5pct font="arial" 'Y=X';
run;

-----

If the equation doesn't have to be on the graph itself, you can put some text in a
'title2' or a 'footnote' statement.

And, of course, you could annotate some text for the equation.

And, if the equation doesn't lend itself to a simple single line of text, you could
create a jpg image containing the equation (created using a fancy word-processor
or other tool) and then annotate that image onto the graph.

-----
N/A
Posts: 0

Re: adding an equation to draw to a plot statement

Thank you for yours answers
Ask a Question
Discussion stats
  • 3 replies
  • 164 views
  • 0 likes
  • 3 in conversation