Contributor
Posts: 53

# Overlay plot with different number of points

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?

Super User
Posts: 12,148

## Re: Overlay plot with different number of points

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.

Contributor
Posts: 53

## Re: Overlay plot with different number of points

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

Super User
Posts: 21,539

## Re: Overlay plot with different number of points

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

Super User
Posts: 12,148

## Re: Overlay plot with different number of points

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.

SAS Super FREQ
Posts: 976

## Re: Overlay plot with different number of points

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;

Contributor
Posts: 53

## Re: Overlay plot with different number of points

Dan,

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

Any thoughts?

Super User
Posts: 21,539

SAS Super FREQ
Posts: 976

## Re: Overlay plot with different number of points

About how many scatter points are involved?

Contributor
Posts: 53

## Re: Overlay plot with different number of points

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

Super User
Posts: 12,148

## Re: Overlay plot with different number of points

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

SAS Super FREQ
Posts: 976

## Re: Overlay plot with different number of points

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;

Discussion stats
• 11 replies
• 714 views
• 0 likes
• 4 in conversation