BookmarkSubscribeRSS Feed
Kimberley
Calcite | Level 5

I have angles that I would like to plot on a cicle? Can I do this with SAS Graph? I have been researching, and can't seem to find the way to do this. Data ranges from 0 to 359 degrees.

Here is a data example:

60

65

76

66

300

359

358

75

66

345

50

265

If anyone has an idea of the approach I could take to do this, I would appreciate it.

Thanks!

Kim

9 REPLIES 9
AnalytX
Fluorite | Level 6

Hi Robert,

Thanks for your great work on graphs and for the SAS codes you share with us!

I am currently working on the same problematic (plot data on a circle, polar plot). I was widely inspired from the programs you mentionned. I would have one just one question:

in the SAS http://robslink.com/SAS/democd4/lead.sas, it is mentioned in comments that "The marker font doesn't center exactly on the coordinate, therefore if you want the markers to be in the exact right location then you'll need to adjust the y-coordinate, or you could draw an annotate 'polygon' which you could center exactly as you like. Since this is just a proof-of-concept example, I'm taking the easy way, and just using the plain old marker font characters". I use "STYLE="special" and I have the same problem, i.e. the location of data in polar plot is not exactly the good one. Do you have an example of the use annotate polygon you explained in the comment of the program in order to have the exact coordinates of data?


Looking forward to hearing from you.


Best regards,



GraphGuy
Meteorite | Level 14

If round markers would suffice, I'd strongly recommend using the built-in annotate 'pie' function - these will center exactly on the x/y coordinate.

An alternative would be to use annotate poly/polycont functions to create a custom polygon.  Here's a simple/trivial example that demonstrates the technique, and draws a diamond-shaped polygon:

data my_anno;

length function color $8 style $35;

xsys='2'; ysys='2'; hsys='3'; when='a';

x=0; y=-.1;

function='poly';

x=x+.01; output;

function='polycont'; style='empty'; color='blue';

y=y+.01; x=x-.01; output;

y=y-.01; x=x-.01; output;

y=y-.01; x=x+.01; output;

run;

pattern1 v=s c=white;

proc gmap data=maps.us map=maps.us anno=my_anno;

id state;

choro state/levels=1 nolegend;

run;

AnalytX
Fluorite | Level 6

Thanks a lot Roger for your answer.

Do you have any available example with the built-in annotate 'pie' function?

Best,

GraphGuy
Meteorite | Level 14

A specific example ... in the 'lead.sas' program you mentioned above, instead of using function='label', you could use function='pie'.  I'll copy-n-paste the relevant before & after code below...

Before ...

data lead; set lead;

length style function color $8 text $30;

xsys='3'; ysys='3'; hsys='3';

function='label';

/* [a few lines left out for brevity] */

style='marker';

if (mcg_dl ge 0) and (mcg_dl <= 5) then do;

  color='graycc';

  text='W';

  size=1.75;

  end;

else if (mcg_dl gt 5) and (mcg_dl <= 10) then do;

  color='cx00ff00';

  text='C';

  size=2;

  end;

else if (mcg_dl gt 10) and (mcg_dl <= 20) then do;

  color='magenta';

  text='U';

  size=2.5;

  end;

else if (mcg_dl gt 20) then do;

  color='cxff0000';

  text='V';

  size=3;

  end;

output;

style='markere'; color='black'; output; /* black outline around each marker */

run;

After ...

data lead; set lead;

length style function color $8;

xsys='3'; ysys='3'; hsys='3';

function='pie'; rotate=360; size=1.5;

/* [a few lines left out for brevity] */

style='psolid';

if (mcg_dl ge 0) and (mcg_dl <= 5) then do;

  color='graycc';

  end;

else if (mcg_dl gt 5) and (mcg_dl <= 10) then do;

  color='cx00ff00';

  end;

else if (mcg_dl gt 10) and (mcg_dl <= 20) then do;

  color='magenta';

  end;

else if (mcg_dl gt 20) then do;

  color='cxff0000';

  end;

output;

style='pempty'; color='black'; output; /* black outline around each marker */

run;

AnalytX
Fluorite | Level 6

Thanks a lot again. I will try this!

Best regards,

AnalytX
Fluorite | Level 6

Hi Robert,

I tested your program and it worked very well.

Thanks a lot.

Best,


Jay54
Meteorite | Level 14

If you transform the polar values to carteaean, and plot using scatter or vector plot.  If you really want radial and circular gridlines, it needs a bit more work.

Here is a blog article I wrote earlier about plotting on a polar axis using GTL but I think you can do it with SGPLOT too.

http://blogs.sas.com/content/graphicallyspeaking/2012/04/09/simpler-is-better/

Rick_SAS
SAS Super FREQ

Is there a response variable that you want to plot?That would result in a polar scatter plot: (theta, r=f(theta)). Currently you've only provided angles.

Are you trying to get a histogram of the angles?  In that case, you'd need to bin the data (perhaps by using PROC UNIVARIATE and the OUTHISTOGRAM= option on the HISTOGRAM statement).

Are you trying to make a dot plot of the data? In that case, set r=1 and make a polar scatter plot (theta, 1).

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
  • 9 replies
  • 3653 views
  • 1 like
  • 5 in conversation