* Richard A. DeVenezia 2/2000; * DSGI example: Comparing an xy plot to an r*theta plot; %let pi = 3.1415926; * assume a day is a 'circle'; data oneday; * generate fake every four minutes data; today = intnx ('DTDAY', datetime (), 0); what = ranuni (1); do hour = 0 to 23; do qh = 0 to 59 by 4; when = today + hour * 3600 + qh * 60; what = what + ranuni (0) - ranuni (0); output; end; end; attrib when label = 'When was measurement made' format=datetime19. what label = 'The measurement' format=7.3 ; keep when what ; run; * determine least what, do not what to plot a negative radius; * least what will become the '0' radius; proc sql noprint; select intnx('dthour', min(when),0) format=best12. , intnx('dthour', max(when),1) format=best12. , min(what) , max(what) into :minWhen, :maxWhen, :minWhat, :maxWhat from oneday; quit; * convert one day to clock like polar coordinates; data onedayP; set oneday; r = what; theta = (when - &minWhen) / (&maxWhen - &minWhen) * 2 * π theta = &pi / 2 - theta; attrib r label = 'The measurement' format=7.3 theta label = 'When was measurement made' ; run; * do a plain old x-y plot for comparison; *ods html path='C:\temp\' file='rad.html'; goptions device=WIN target=WINPRTC hsize= vsize= ftext=swiss rotate=landscape; goptions goutmode=replace ; *goptions device=GIF target=WINPRTC hsize= vsize= xpixels=82 ypixels=64; symbol1 v=dot h=1pct i=join c=black; axis1 order=&minWhen to &maxWhen by dtday minor=(number=23); title "Measurements for a day"; proc gplot data=oneday gout=work.compare; plot what * when / grid name='ONEDAY' haxis=axis1; run; quit; goptions goutmode=append; goptions hsize=5in vsize=5in; * goptions xpixels=64 ypixels=64; * do a polar annotate plot; %macro XY(n,r,theta); %* assume rMin exists and value is where origin should be; x&n = (&r-rMin)*cos(&theta); y&n = (&r-rMin)*sin(&theta); %mend; * These mess up aspect ratio if present; title; footnote; * labeling the theta and r reference lines is left as an exercise; data _null_; rc = gset ('CATALOG', 'WORK', 'COMPARE'); rc = ginit(); rc = graph('CLEAR', 'ONEDAY'); * fudge radial offset away from center; rMin = &minWhat - .10 * (&maxWhat-&minWhat); rMax = &maxWhat + .10 * (&maxWhat-&minWhat); rRange = rMax - rMin ; rc = gset ('VIEWPORT', 1, 0,0, 1,1); rc = gset ('WINDOW', 1, -rRange, -rRange, rRange, rRange); rc = gset ('TRANSNO', 1); * plot some theta reference lines; nTref = 24; rc = gset ('LINTYPE', 33); do i = 1 to nTref; theta = (i-1) / nTref * 2 * &pi ; %XY(1,&minWhat,theta); %XY(2,rMax,theta); rc = gdraw ('LINE', 2, x1,x2, y1,y2); end; * plot some radial reference lines; nRref = 6; rc = gset ('LINTYPE', 33); do i = 1 to nRref; r = i / nRref * (&maxWhat-&minWhat); rc = gdraw ('ARC', 0,0, r, 0, 360); end; * plot the data radial reference lines; rc = gset ('LINTYPE', 1); n = 1; eod = 0; do while (not(eod)); set onedayP end=eod; if n > 1 then do; x1=x2; y1=y2; %XY(2,r,theta); rc = gdraw('LINE', 2, x1,x2, y1,y2); end; else do; %XY(2,r,theta); rc = gdraw('LINE', 1, x2,y2); end; n+1; end; rc = graph('UPDATE');*,'NOSHOW'); rc = gterm(); stop; run; *ods html close;