2023年8月24日木曜日

正方形のplotを描画する話

 たまに散布図を出力するときにplotを正方形にしてください、と依頼を受けることがあります。気持ちはわかるがどうすんねんという話ですが、ちょうどsgplotステートメントにaspectオプションがあり、これに 1を指定するとplotが正方形になります。aspectオプションは0-1の幅で指定できます。

詳細はsasのヘルプページのASPECT=positive-number欄に記載があります。

specifies the aspect ratio of the plot’s wall area. The ratio is expressed as a positive decimal fraction representing wall-height divided by wall-width. For example, 0.75 is a 3/4 aspect ratio, and 1.0 is a square aspect ratio.

Small numbers, such as 0.01, produce a short, wide rectangular area. Larger numbers yield a taller, narrower rectangular area.

https://documentation.sas.com/doc/en/pgmsascdc/9.4_3.5/grstatproc/p073bl97jzadkmn15lhq58yiy2uh.htm#p00zvhaib2skg9n10khojgxdigzh



以下プログラム

data FDAT ;

    call streaminit(1234) ;

    do i = 1 to 10 ;

        AVAL = rand('uniform') *100 ;

        output ;

    end ;  

run ;

%let _out = %sysfunc(getoption(work)) ;

ods listing gpath = "&_out" ;

ods graphics on / reset= all noborder imagename = "test" imagefmt= png ;

proc sgplot data = FDAT nowall noautolegend aspect = 1 ;

    scatter x = I y = AVAL ;

run ;