1. 程式人生 > 其它 >SAS BOXPLOT綜合

SAS BOXPLOT綜合


*
drawtext和layout gridded中的entry都可以展示一段文字
drawtext值是相當於找個地方寫入文字,對佈局沒影響
layout gridded中的entry會佔據一部分佈局空間

axistable 和blockplot都可以畫出來資料,但blockplot不能用discreteattrvar
axistable 可以使用colorgroup和discreteattrvar對應起來

插入referenceline 或者dropline時,記得座標軸型別 type = linear以或其它,不能為離散型
dropline可以控制線的開始位置,不貫穿整個layout

blockplot中的valueHalign = start可以使得資料顯示在最標軸刻度上方,而不是其它位置

適當的用pad = () outerpad = ()調整位置

BOXPLOT中的connect就是連線,把不同boxplot中的min max mean或其它用線連起來,display = (connect)
display = (caps)顯示極值處的橫線

innermargin和layout gridded可以巢狀在layout overlay中,主要是畫個文字或者統計量
innermargin 還可以巢狀在PROTOTYPE中

;

data heart;
do visitn  = 1,2,3,4,5,6,7;
    do subjid = 1 to 50;
        response 
= ranuni(1)*54;drug = 'Drug A';priorNum = put(int(ranuni(1)*23 + 2),best.);afterNum = put(int(ranuni(1)*14 + 2),best.); output; response = ranuni(1)*54;drug = 'Drug B';priorNum = put(int(ranuni(1)*23 + 2),best.);afterNum = put(int(ranuni(1)*14 + 2),best.); output; response
= ranuni(1)*54;drug = 'Drug C';priorNum = put(int(ranuni(1)*23 + 2),best.);afterNum = put(int(ranuni(1)*14 + 2),best.); output; end; end; run; proc sort data = heart; by drug visitn subjid; run; data heart; set heart; by drug visitn subjid; retain _num _num2; if first.visitn then _num = priorNum; else priorNum = _num; if first.visitn then _num2 = afterNum; else afterNum = _num2; if 48 < response or response > 2 then do; response_1 = response; end; run; proc template; define statgraph _boxplot; begingraph / subpixel = on border = false; legenditem name = '1' type = markerline / label = 'Drug A' labelattrs = (color = black family = 'Courier New' size = 9pt) markerattrs = (color = red symbol = plus) lineattrs = (color = red) outlineattrs = (color = white); legenditem name = '2' type = markerline / label = 'Drug B' labelattrs = (color = black family = 'Courier New' size = 9pt) markerattrs = (color = green symbol = circle) lineattrs = (color = green) outlineattrs = (color = green); legenditem name = '3' type = markerline / label = 'Drug C' labelattrs = (color = black family = 'Courier New' size = 9pt) markerattrs = (color = blue symbol = DiamondFilled) lineattrs = (color = blue) outlineattrs = (color = blue); discreteattrmap name = 'selfName1' / ignorecase = true; value 'Drug A' / lineattrs = GraphData1(color = red pattern = solid) markerattrs = GraphData1(color = red symbol = plus) fillattrs = GraphData1(color = red ) textattrs = (color = red); value 'Drug B' / lineattrs = GraphData1(color = green pattern = solid) markerattrs = GraphData1(color = green symbol = Circle) fillattrs = GraphData1(color = green ) textattrs = (color = green); value 'Drug C' / lineattrs = GraphData1(color = blue pattern = solid) markerattrs = GraphData1(color = blue symbol = DiamondFilled) fillattrs = GraphData1(color = blue ) textattrs = (color = blue); enddiscreteattrmap; discreteattrvar attrvar = selfName1_ var = drug attrmap = 'selfName1'; layout lattice / rows = 2 columndatarange = union rowweights = (0.15 0.85) rowgutter = 0.2; columnaxes; columnaxis / display = (ticks tickvalues label) label = 'Visit'; endcolumnaxes; layout overlay / border = false walldisplay = none; /* entry halign = left 'Number of subject before the visit' / valign = top textattrs = (family = 'Courier New' size = 9pt) pad = (left = 40pt);*/ /* drawtext textattrs = (family = 'Courier New' size = 9pt ) "Number of subject before the visit" / x = 0.5 y = 100 width = 100 anchor = left drawspace = layoutpercent ; */ /* blockplot x = visitn block = priorNum / class = drug display = (values label) valuehalign = start valueattrs = (family = 'Courier New' size = 9pt) labelattrs = (family = 'Courier New' size = 9pt) ;*/ /* layout gridded / rows = 1 columns = 1 order = columnmajor autoalign = (topleft);*/ /* entry halign = left textattrs = (family = 'Courier New' size = 9pt) 'Number of subject before the visit' / valign = top;*/ /* endlayout;*/ axistable x = visitn value = priorNum / class = drug colorgroup = selfName1_ headerlabel = "Number of subject before the visit" display = (values label) headerlabelattrs = (family = 'Courier New' size = 9pt) labelattrs = (family = 'Courier New' size = 9pt) valueattrs = (family = 'Courier New' size = 9pt); endlayout; layout overlay / x2axisopts = (type = linear display = none ); boxplot x = visitn y = response / xaxis= x2 group = selfName1_ groupdisplay = cluster connect = max connectattrs=( Pattern=solid Thickness=1) display=(outliers caps mean); /* referenceline x = 7.1 / lineattrs = (pattern = dot thickness = 2 color = black);*/ referenceline y = 45 / lineattrs = (pattern = dot thickness = 2 color = black) ; dropline x = 5.5 y = 0 / xaxis = x2 dropto = x lineattrs = (pattern = dot thickness = 2 color = black); discretelegend '1' '2' '3' / location = outside halign = center valign = bottom border = false across = 3 outerpad = (top = 50); innermargin / pad = (top = 5); blockplot x = visitn block = afterNum / class = drug display = (values label) VALUEHALIGN=start; endinnermargin; endlayout; endlayout; endgraph; end; run; ods html; proc sgrender data = heart template = _boxplot; run;