我想将两个情节合并为一个。每个图都通过当年相应的累积测试结果来表示当前/不存在的观测值的比例
所以在情节中,我希望看到并排的测试成绩组的条形图,但要计算从存在到不存在的数量
代表这个问题,这是我目前所拥有的:
data test_scores;
do i = 1 to 200;
score = ranuni(200);
output;
end;
drop i;
run;
data test_scores_2;
set test_scores;
if _n_ le 100 then flag = 0;
else flag = 1;
run;
data test_scores_2_0 test_scores_2_1;
set test_scores_2;
if flag = 0 then output test_scores_2_0;
else if flag = 1 then output test_scores_2_1;
run;
PROC GCHART
DATA=test_scores_2_0
;
VBAR
score
/
CLIPREF
FRAME
LEVELS=20
TYPE=PCT
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
;
RUN;
QUIT;
PROC GCHART
DATA=test_scores_2_1
;
VBAR
score
/
CLIPREF
FRAME
LEVELS=20
TYPE=PCT
COUTLINE=BLACK
RAXIS=AXIS1
MAXIS=AXIS2
;
RUN;
QUIT;
目前,条形图的总和应为100% 不存在的金条总计应为100%
TIA
答案 0 :(得分:1)
proc sgplot
进行营救。使用group=
选项可以指定两个单独的组。将透明度设置为50%,以便一个直方图不会覆盖另一个。
proc sgplot data=test_scores_2;
histogram score / group=flag transparency=0.5 binwidth=.05;
run;
答案 1 :(得分:1)
通过Proc GCHART
,您可以使用VBAR
选项GROUP=
和G100
来获得代表组中百分比的条形图。当组的计数不同时,这很有用。
SUBGROUP=
选项根据子组变量的不同值分割竖线,并自动生成与子组相对应的颜色和图例。
当SUBGROUP
变量(或值)与组1:1对应时,结果是每个组的图表颜色不同,并且图例对应于组。
例如,修改数据,使第1组的计数为50,第2组的计数为150:
data test_scores;
do _n_ = 1 to 200;
score = ranuni(200);
flag = _n_ > 50;
output;
end;
run;
axis1 label=("score");
axis2 ;
axis3 label=none value=none;
PROC GCHART data=test_scores;
VBAR score
/ levels=10
GROUP=flag G100
SUBGROUP=flag
SPACE=0 TYPE=PERCENT freq gaxis=axis3 maxis=axis1 ;
run;
输出
类似的图表显示了具有与组值不同的值的子组变量的作用。
data test_scores;
do _n_ = 1 to 200;
subgroup = ceil(5 * ranuni(123)); * random 1 to 5;
score = ranuni(200);
flag = _n_ > 50;
output;
end;
run;
axis1 label=("score");
axis2 ;
axis3 label=none value=none;
PROC GCHART data=test_scores;
VBAR score
/ levels=10
GROUP=flag G100
SUBGROUP=subgroup /* has integer values in [1,5] */
SPACE=0 TYPE=PERCENT freq gaxis=axis3 maxis=axis1;
run;