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-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

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