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

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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