гистограмма конечной точки SAS sgplot

#sas #histogram

#sas #гистограмма

Вопрос:

Я пытаюсь изменить гистограмму в SAS proc sgplot так, чтобы ячейки графически не были центрированы в средней точке. Скорее, я хотел бы, чтобы они были от 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;
  

Спасибо.

Pyll

Ответ №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 является средней точкой для первой ячейки, а не нижней конечной точкой. Вы хотите, чтобы 2.5 была средней точкой, поэтому определите ее таким образом.

GTL действительно позволяет вам определять столбцы так, как вы хотите, и возможно, что в более поздней версии эта опция может появиться в SGPLOT. Обратите внимание на xvalues=leftpoints , это то, что управляет тем, как структурированы ячейки.

  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;