BookmarkSubscribeRSS Feed
Doug
Calcite | Level 5

I have a scatter plot upon which I must overlay three other items:

1. Centroid value of X and Y (one value with marker)

2. A circle +/- 2.5 units of the centroid

3. A circle of +/-5.0 units of the centroid

What is the most effective way of doing this?

11 REPLIES 11
ballardw
Super User

Which procedure do you plan on using?

Depending on procedure and version of SAS the second 2 are probably easiest with an annotate data set as you specify a a coordinate and radius for a circle. Which would require about 3 lines of code. Look at the %Circle macro in the annotate facility.

Doug
Calcite | Level 5

I originally planned to use SGPLOT  - the software version I have is 9.2 TS2M3

Reeza
Super User

GTL might be a good option if there's an easy way to draw a circle in it.

ballardw
Super User

Simplest I can think of:

 

data junk;

x = 5; y=5;

run;

proc sgplot data=junk;

scatter x=x y=y /markerattrs=(symbol=circlefilled) name='yes';

scatter x=x y=y /markerattrs=(symbol=circle size=25mm) name='no';

scatter x=x y=y /markerattrs=(symbol=circle size=50mm) name='no2';

keylegend 'yes' /title='Legend';

run;

The size and units would likely change depending on the size of your final display and you may want to play with axis defintions to make it prettier.

DanH_sas
SAS Super FREQ

If circles are not important, you can use XERRORUPPER/LOWER and YERRORUPPER/LOWER to show the +/-2.5 and +/-5.0 limits. You should need only two scatter overlays to show these limits, the first scatter can show the real point and the +/- 2.5 limits. The code will look something like this:

proc sgplot data=somedata nocycleattrs;

scatter x=x y=y / xerrorupper=xulimit50 xerrorlower=xllimit50 yerrorupper=yulimit50 yerrorlower=yllimit50 markerattrs=(size=0);

scatter x=x y=y / xerrorupper=xulimit25 xerrorlower=xllimit25 yerrorupper=yulimit25 yerrorlower=yllimit25;

run;

Doug
Calcite | Level 5

Dan,

Circles are kind of important since they are the companion to tables which show the actual counts

Any thoughts?

DanH_sas
SAS Super FREQ

About how many scatter points are involved?

Doug
Calcite | Level 5

Probably about 50 per plot  - I don't have SAS 9.3 will the 9.3 GTL still work?

ballardw
Super User

Or perhaps proc gplot with a bubble plot with multiple requests overlayed.

DanH_sas
SAS Super FREQ

If you're going to use the ODS Graphics systems to do this at SAS 9.2, the only way that comes to mind (warning: this is brute force) is to use ELLIPSEPARM statements in GTL. You would have to write a macro loop to generate an ELLIPSEPARM statement for each circle needed in the plot. Here is some pseudo-code for the idea:

proc template;

define statgraph myscatter;

begingraph;

layout overlay;

  scatterplot x=x y=y;

  %do %p=1 %to numberOfCircles;

       ellipseparm semimajor=%unit semiminor=%unit slope=0 xorigin=%x yorigin=%y;

  %end;

endlayout;

endgraph;

end;

run;

proc sgrender data=somedata template=myscatter; run;

SAS Innovate 2025: Save the Date

 SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!

Save the date!

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
  • 11 replies
  • 2377 views
  • 0 likes
  • 4 in conversation