0

我有两个想要合并为一个的地块。每个图通过其相应的当年累积测试结果表示存在/不存在观察的比例

所以在情节上,我希望看到条形图,并排显示测试分数组,但计算存在到不存在的数量

为了表示这个问题,这就是我目前所拥有的:

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

4

2 回答 2

1

proc sgplot救援。使用该group=选项指定两个单独的组。将透明度设置为 50%,这样一个直方图就不会覆盖另一个。

proc sgplot data=test_scores_2;
    histogram score / group=flag transparency=0.5 binwidth=.05;
run;

在此处输入图像描述

于 2019-03-26T17:28:04.663 回答
1

Proc GCHART您可以使用选项VBARGROUP=获得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;

在此处输入图像描述

于 2019-03-27T13:01:21.693 回答