BookmarkSubscribeRSS Feed
brophymj
Quartz | Level 8

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..

4 REPLIES 4
Jay54
Meteorite | Level 14

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

brophymj
Quartz | Level 8

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;

Jay54
Meteorite | Level 14

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;

GraphGuy
Meteorite | Level 14

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

 

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 4 replies
  • 2144 views
  • 0 likes
  • 3 in conversation