Data visualization with SAS programming

How to plot data on a circle?

Reply
Occasional Contributor
Posts: 12

How to plot data on a circle?

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

SAS Employee
Posts: 963

Re: How to plot data on a circle?

Contributor
Posts: 57

Re: How to plot data on a circle?

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,



SAS Employee
Posts: 963

Re: How to plot data on a circle?

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;

Contributor
Posts: 57

Re: How to plot data on a circle?

Thanks a lot Roger for your answer.

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

Best,

SAS Employee
Posts: 963

Re: How to plot data on a circle?

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;

Contributor
Posts: 57

Re: How to plot data on a circle?

Thanks a lot again. I will try this!

Best regards,

Contributor
Posts: 57

Re: How to plot data on a circle?

Hi Robert,

I tested your program and it worked very well.

Thanks a lot.

Best,


SAS Super FREQ
Posts: 1,044

Re: How to plot data on a circle?

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/

SAS Super FREQ
Posts: 3,234

Re: How to plot data on a circle?

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).

Post a Question
Discussion Stats
  • 9 replies
  • 1193 views
  • 1 like
  • 5 in conversation