Data visualization with SAS programming

Putting arrows on a scatter graph

Reply
Super Contributor
Posts: 256

Putting arrows on a scatter graph

Is it possible to put arrows connecting points on a scatter plot?

If my scatter plot consists of 4 point can I show a line with an arrow connecting:

point1-point2

point1-point4

and so on..

SAS Super FREQ
Posts: 1,104

Re: Putting arrows on a scatter graph

Yes, use a VECTOR plot overlay.  Or use SERIES or SPLINE with SAS 9.4M3.

Super Contributor
Posts: 256

Re: Putting arrows on a scatter graph

Thanks Sanjay. I'm not sure if this will work though. It seems you can only have arrows pointing from the origin or some other point to every other point in the scatter plot. I want an arrow connecting each consecutive point in a particular sequence. I want to be able to specify a "route" around the scatter plot using arrows. Can this be done?

data obs;

   do i= 1 to 8;

      x= round(100* ranuni(123),1);

      y= round(100* ranuni(789),1);

      output;

   end;

run;


title "Scatter Chart";
proc sgplot data=obs;

  vector x=x y=y
   / yorigin=32 xorigin=75
     datalabel;
run;
title;

SAS Super FREQ
Posts: 1,104

Re: Putting arrows on a scatter graph

Yes, you can.  XOrigin and YOrigin can be other columns in the data.

You need 4 columns, two for (x, y) and two for (xprev, yprev).  Then set your data so xprev is same as x for the next set of points.  For first point, they will be missing.

vector x=x y=y / xorigin=xprev yorigin=yprev;

SAS Employee
Posts: 967

Re: Putting arrows on a scatter graph

Here's how to do it with traditonal SAS/Graph Proc Gplot and Annotate ...

 

data obs;
do i= 1 to 8;
x= round(100* ranuni(123),1);
y= round(100* ranuni(789),1);
output;
end;
run;

 

data anno_arrows; set obs;
length function $8;
xsys='2'; ysys='2'; when='a';
if _n_=1 then function='move';
else function='arrow'; style='filled'; angle=30; line=1.8; color='red';
run;

 

symbol1 value=circle color=blue height=1.0 interpol=none;


proc gplot data=obs anno=anno_arrows;
plot y*x;
run;

 

gplot9.png

 

Ask a Question
Discussion stats
  • 4 replies
  • 448 views
  • 0 likes
  • 3 in conversation