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;
本文来自博客园,作者:Iving,转载请注明原文链接:https://www.cnblogs.com/SAS-T/p/15455581.html