Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
genemroz
Quartz | Level 8

Esteemed Advisers:

 

I'm trying but failing to get annotate a scatterplot with arrows.  Below is a simplified version of my code that demonstrates the problem.  Probably a simple fix that I'm just not seeing.

 

Thanks in advance for your help,

 

Gene

 

options mprint symbolgen;

/*Create scatter plot dataset*/
data work.plot_data;
	input lat lon alt;
	datalines;
34.0 -105.0 120
33.0 -104.0 120
;
run;

/*Create arrow dataset file*/
data work.arrow_data;
	input latbeg lonbeg latend lonend;
	datalines;
34.5 -105.5 34.0 -105.0
33.5 -104.5 33.0 -104.0
;
run;

/*Create arrow_anno dataset*/
data arrow_anno;
set work.arrow_data;
retain xsys ysys '2' hsys '3' when 'a';
function='arrow';
x1=lonbeg;
y1=latbeg;
x2=lonend;
y2=latend;
color='black';
line=2;
size=.7;
style='FILLED';
run;

ods graphics;
/*Generate plot*/
proc sgplot data=work.plot_data sganno=arrow_anno aspect=1;
Title "Anno Arrow Test";
	scatter x=lon y=lat;
	xaxis grid min=-106 max=-103 minorgrid;
	yaxis grid min=30 max=35 minorgrid;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14
data plot_data;
input lat lon alt;
datalines;
34.0 -105.0 120
33.0 -104.0 120
;
run;

data arrow_data;
input latbeg lonbeg latend lonend;
datalines;
34.5 -105.5 34.0 -105.0
33.5 -104.5 33.0 -104.0
;
run;

data arrow_anno; set arrow_data;
function='arrow';
shape='filled';
layer='front';
linecolor='black';
linethickness=1;
drawspace='datavalue';
x1=lonbeg;
y1=latbeg;
x2=lonend;
y2=latend;
run;

proc sgplot data=plot_data sganno=arrow_anno aspect=1;
Title "Anno Arrow Test";
	scatter x=lon y=lat;
	xaxis grid min=-106 max=-103 minorgrid;
	yaxis grid min=30 max=35 minorgrid;
run;

anno_arrow.png

View solution in original post

5 REPLIES 5
Jay54
Meteorite | Level 14

The SGANNO feature uses a different data set than the SAS/GRAPH Annotation data set.

You need different variable names and values.

See:  https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/n17wm229xfidj7n1nfx67jsb3yj5.htm

 

Also see for overview :   https://support.sas.com/rnd/datavisualization/papers/Annotate_Your_SGPLOT_Graphs.pdf

 

Also note, you could easily use the VECTOR plot or SERIES plot in your use case.

GraphGuy
Meteorite | Level 14
data plot_data;
input lat lon alt;
datalines;
34.0 -105.0 120
33.0 -104.0 120
;
run;

data arrow_data;
input latbeg lonbeg latend lonend;
datalines;
34.5 -105.5 34.0 -105.0
33.5 -104.5 33.0 -104.0
;
run;

data arrow_anno; set arrow_data;
function='arrow';
shape='filled';
layer='front';
linecolor='black';
linethickness=1;
drawspace='datavalue';
x1=lonbeg;
y1=latbeg;
x2=lonend;
y2=latend;
run;

proc sgplot data=plot_data sganno=arrow_anno aspect=1;
Title "Anno Arrow Test";
	scatter x=lon y=lat;
	xaxis grid min=-106 max=-103 minorgrid;
	yaxis grid min=30 max=35 minorgrid;
run;

anno_arrow.png

genemroz
Quartz | Level 8
Yes, I get confused about the different syntax for the different annotate systems.

Thanks for your help,

Gene
BAGaucho
Obsidian | Level 7

Unless you really need to use annotation data, another method could be using Symbolchar statement to create the arrow sign you want. You can use textattrs and scale to fine tuning the arrow shape. There are more than 100 arrow shapes from Unicode. If you go to https://en.wikipedia.org/wiki/Arrows_(Unicode_block) you can choose one as you need. 

 

Then use the scatter statement to put the arrow(s) as you want. If you need to attach it to real data, just create the location of the x value(s) of the arrow and the y value(s). Yes, of course, you can change the arrow shape with markerattrs.

 

Sorry, I can't give you the actual code, but you already use scatter statement so it won't be hard, I think. Add markerattrs, name, legendlabel if you need to make your plot look more explainable. I am trying not to use annotation as much as possible unless it's definitely necessary to use.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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
  • 5 replies
  • 1919 views
  • 4 likes
  • 4 in conversation