turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- How to plot data on a circle?

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

07-26-2012 08:31 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kimberley

07-26-2012 08:39 AM

You'll probably need to use SAS/Graph 'annotate' and the 'pie' function.

I'm not sure exactly how you'd like to plot your angles, but here are a few examples plotting circular data:

SAS/Graph - Custom Flight Direction chart

http://robslink.com/SAS/democd15/compass_info.htm

Flight Direction chart - using custom SAS/Graph

http://robslink.com/SAS/democd17/wind_info.htm

Lead Exposure (Custom SAS/Graph Windrose/Polar type graph)

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

03-19-2013 07:28 PM

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,

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to AnalytX

03-20-2013 09:16 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

03-26-2013 08:44 AM

Thanks a lot Roger for your answer.

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

Best,

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to AnalytX

03-26-2013 08:55 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

03-26-2013 09:04 AM

Thanks a lot again. I will try this!

Best regards,

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

04-03-2013 06:13 PM

Hi Robert,

I tested your program and it worked very well.

Thanks a lot.

Best,

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kimberley

07-26-2012 09:14 AM

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/

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Kimberley

07-26-2012 10:51 AM

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