【问题标题】:endpoint histogram SAS sgplot端点直方图 SAS sgplot
【发布时间】:2014-07-03 16:26:29
【问题描述】:

我正在尝试修改 SAS proc sgplot 中的直方图,以使 bin 不会以图形方式居中于中点。相反,我希望它们从 0 到 5、5 到 10 等。按照目前的图表方式,我在 0 处得到了这个奇怪的“半条”——它的厚度不合适,看起来很奇怪。

我不依赖于使用 sgplot,如果我仍然可以获得所需的叠加直方图,我可以使用单变量或 proc 模板。这是我的数据:

data have;
    input x y;
cards;
1 . 
5 .  
6 . 
20 . 
13 . 
4 . 
2 . 
2 . 
7 . 
4 . 
17 . 
33 . 
2 . 
. 2 
. 15 
. 4 
. 10 
. 35 
. 20 
. 6 
. 14
;
run;

proc sgplot data=have;
    histogram x /  fillattrs=graphdata1 name='s' legendlabel='x' 
                       transparency=0.5 binstart=0 binwidth=5; 
    histogram y / fillattrs=graphdata2 name='d' legendlabel='y' 
                       transparency=0.5  binstart=0 binwidth=5; 
    keylegend 's' 'd' / location=inside position=topright across=1;
    xaxis display=(nolabel) label='label' min=0 max=40;
 run;

谢谢。

皮尔

【问题讨论】:

    标签: sas histogram


    【解决方案1】:
    proc sgplot data=have;
        histogram x /  fillattrs=graphdata1 name='s' legendlabel='x' 
                           transparency=0.5 binstart=2.5 binwidth=5; 
        histogram y / fillattrs=graphdata2 name='d' legendlabel='y' 
                           transparency=0.5  binstart=2.5 binwidth=5; 
        keylegend 's' 'd' / location=inside position=topright across=1;
        xaxis display=(nolabel) label='label' min=0 max=40;
     run;
    

    BINSTART 参数是第一个 bin 的中点,而不是低端点。您希望 2.5 成为中点,所以这样定义。

    GTL 确实允许您以您想要的方式定义条形图,并且在以后的版本中,此选项可能会出现在 SGPLOT 中。请注意 xvalues=leftpoints,它控制了 bin 的结构。

     proc template;
     define statgraph myhist;
        begingraph;
            layout overlay/cycleattrs=true x2axisopts=(labelFitPolicy=Split) xaxisopts=( display=( ticks tickvalues line ) 
                            type=linear linearopts=( viewmin=0 viewmax=40 ) );
    
                histogram x/binstart=0 binwidth=5 xvalues=leftpoints datatransparency=0.5 legendlabel='x'
                            name='x' fillattrs=graphdata1;
                histogram y/binstart=0 binwidth=5 xvalues=leftpoints datatransparency=0.5 legendlabel='y' 
                            name='y' fillattrs=graphdata2;
                   DiscreteLegend "x" "y"/ Location=Inside across=1 halign=right valign=top;
            endlayout;
        endgraph;
    end;
    quit;
    
    proc sgrender template=myhist data=have;
    run;
    

    【讨论】:

    • 谢谢,@Joe。这正是我所需要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-03-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多