- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Thanks for your help,
Gene
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Or, you can use the VECTOR statement in SGPLOT procedure.
https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p1wtsx90517bf4n12fpaaeh6za0l.htm
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
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.