我使用SGPLOT程序在SAS中生成垂直箱图,以下是代码。我无法通过各种类别订购箱图,我想通过升序测量变量和胆固醇来定购它们,但似乎无法实现这一点。此外,我希望能够更改不同级别的类别变量的名称" weight_status"甚至可能考虑按字母顺序绘制箱形图。
proc sgplot data=sashelp.heart;
title "Cholesterol Distribution by Weight Class";
vbox cholesterol / category=weight_status GROUPORDER= descending;
run;
title
有人可以协助吗?
答案 0 :(得分:2)
要使用GROUPORDER=
,您必须使用GROUP=
而不是类别,因此可行:
title "Cholesterol Distribution by Weight Status";
proc sgplot data=sashelp.heart;
where Weight_Status NE '';
vbox cholesterol /
GROUP=weight_status
GROUPORDER= descending;
run;
title
我必须添加where子句,因为缺少的类别被抑制但缺少的组不是。
为此,您必须将该均值添加到数据集中,例如:
proc sql;
create view temp_heart as
select individu.weight_status, cholesterol, group_mean
from sashelp.heart individu inner join
( select weight_status, mean(cholesterol) as group_mean
from sashelp.heart
group by weight_status ) collection
on individu.weight_status EQ collection.weight_status;
quit;
我有两种方式可以显示这个
数字类别按数字顺序排序,因此可以完成工作,但也可以在图例中显示您的重量类,我将它们用作组
proc sgplot data=temp_heart;
where Weight_Status NE '';
vbox cholesterol /
Category=group_mean
GROUP=weight_status ;
run;
现在这很快又脏,我同意,所以我有另一个选择
使用Proc Format
为平均值创建格式,然后使用该格式
proc sql;
create table temp_means as
select 'mean2status' as fmtname
, mean(cholesterol) - 1E-8 as start
, mean(cholesterol) + 1E-8 as end
, weight_status as label
from sashelp.heart
group by weight_status;
quit;
proc format cntlin=temp_means (where=(label NE '')) cntlout=temp_check;
run;
proc sgplot data=temp_heart (where=(weight_status NE ''));
format group_mean mean2status.;
vbox cholesterol /
category=group_mean;
run;
不幸的是,在工作之前,我不得不在平均值之间使用2E-8宽的间隔。