Data visualization with SAS programming

annotated data in gplot and sgplot

Reply
Occasional Contributor fy1
Occasional Contributor
Posts: 5

annotated data in gplot and sgplot

Hi ,

I made an annotated dataset to try out the sgplot, and found the result is not what I expected, Could you tell me what i should do to make my existing annotated datasets are still valuable in new powerful procedure sgplot?   

 

Thank you so very much.

 

****************************************************************************;

data xx;
do Dt='1JAN2016'd to '1jan2017'd;
retain CNT 1;
cat1=rand('bernolli',0.3);
cat2=rand('bernolli',0.5);
mon=month(DT);
output;
end;
run;
proc means data=xx sum;
var CAT1 CAT2;
class MON ;
output out=res_cnt sum=/autoname;
run;

data plt;
set res_cnt;
x=_n_;
y=CAT1_sum;
if mon>.;
run;
%annomac;
data plt_anno ;
set plt;
%dclanno;
%line(0,0,10,10,black,1,1);
%line(0,0,12,22,black,1,1);
%line(0,0,22,33,black,1,1);
%line(0,0,32,44,black,1,1);

run;
axis1;
axis2;
proc ganno annotate=plt_anno;
title1 "ganno";
run;
proc gplot data=plt;
title1 "gplot";
plot y*mon/anno=plt_anno;
run;

proc sgplot data=plt sganno=plt_anno;
title1 "sgplot";
scatter x=mon y=y;
run;

***************************************************************************;

Grand Advisor
Posts: 17,360

Re: annotated data in gplot and sgplot

The advantage to SGPLOT is that sometimes there's an easier/better way to do things.

 

Both codes generate a standard scatter plot but the GPLOT has some random lines? 

 

In SGPLOT I would consider using REFLINE/POLYGON/TEXT instead to mimic some of the functionality you had with the annotation sets. I'm not sure this would work in your exact situation/example.

 

SAS Super FREQ
Posts: 1,081

Re: annotated data in gplot and sgplot

Annotation in SGPLOT is NOT the same as in GPLOT.  You cannot use the same data set.  That is one reason the option name is called SGANNO, not ANNO.  See this article on some information.

 

That said, there are better ways to create graphs in SG procedures without use of annotation as alluded to by Reeza.  See Getting Started articles in Graphically Speaking Blog for many articles on using plot layers.  

Occasional Contributor fy1
Occasional Contributor
Posts: 5

Re: annotated data in gplot and sgplot

Thanks, Sanjay and Reeza, I got it, The sgplot is not going to replace the gplot, we still need old annotate library to build some graphs like the example I randomly drew.
Ask a Question
Discussion stats
  • 3 replies
  • 128 views
  • 0 likes
  • 3 in conversation