SAS图形:将2个图的轴与格子排对齐 [英] SAS GRAPH: align axis for 2 plots with lattice rows

查看:1131
本文介绍了SAS图形:将2个图的轴与格子排对齐的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



这个问题我很困扰自己这个问题,我真的找不到解决方案,我希望在这里张贴,有人会帮助。是这个2格子行模板我不能对齐轴。





现在我详细介绍了我用代码重现的所有内容每一步:



我有这个情节

这里的代码都是对于图表和示例数据集(这是一个简单的版本: http://

示例数据集:


  data immune; 
格式sival f6.3;
输入trt $ 1-8 cyc $ 10-18 pt lbparm $ xval sival;
卡;
药物A周期1 1 C3 1 1.120
药物A周期1 1 C4 1 0.147
药物A周期1 1 C3 2 1.080
药物A周期1 1 C4 2 0.131
药物A周期1 1 C3 3 0.887
药物A周期1 1 C4 3 0.113
药物A周期2 1 C3 4 1.440
药物A周期2 1 C4 4 0.278
药物A周期2 1 C3 5 1.180
药物A周期2 1 C4 5 0.234
药物A周期2 1 C3 6 1.360
药物A周期2 1 C4 6 0.281
药物A周期3 1 C3 7 1.190
药物A周期3 1 C4 7 0.282
药物A周期3 1 C3 8 1.000
药物A周期3 1 C4 8 0.228
药物A周期3 1 C3 9 1.040
药物A循环3 1 C4 9 0.228
药物A循环4 1 C3 10 0.917
药物A循环4 1 C4 10 0.163
药物A循环4 1 C3 11 0.789
药物A周期4 1 C4 11 0.136
药物A周期4 1 C3 12 0.861
药物A周期4 1 C4 12 0.148
药物A周期1 2 C3 1 1.180
药物A周期1 2 C4 1 0.264
药物A周期1 2 C3 2 0.942
药物A周期1 2 C4 2 0.184
药物A周期1 2 C3 3 1.010
药物A周期1 2 C4 3 0.160
药物A周期2 2 C3 4 1.050
药物A周期2 2 C4 4 0.134
药物A周期2 2 C3 5 0.980
药物A周期2 2 C4 5 0.120
药物A周期2 2 C3 6 1.020
药物A周期2 2 C4 6 0.126
药物A周期3 2 C3 7 0.961
药物A周期3 2 C4 7 0.110
药物A周期3 2 C3 8 0.859
药物A周期3 2 C4 8 0.091
药物A周期3 2 C3 9 0.928
药物A周期3 2 C4 9 0.097
药物A周期4 2 C3 10 1.380
药物A周期4 2 C4 10 0.330
药物A周期4 2 C3 11 1.210
药物A周期4 2 C4 11 0.281
药物A周期4 2 C3 12 1.180
药物A周期4 2 C4 12 0.278
药物A周期1 3 C3 1 1.180
药物A周期1 3 C4 1 0.269
药物A周期1 3 C3 2 1.010
药物A周期1 3 C4 2 0.213
药物A周期1 3 C3 3 1.040
药物A周期1 3 C4 3 0.200
药物A周期2 3 C3 4 1.200
药物A周期2 3 C4 4 0.332
药物A周期2 3 C4 5 0.371
药物A周期2 3 C4 6 0.316
药物A周期3 3 C4 7 0.271
药物A周期3 3 C3 8 1.050
药物A周期3 3 C4 8 0.246
药物A周期3 3 C3 9 1.100
药物A周期3 3 C4 9 0.248
药物A周期4 3 C3 10 1.090
药物A周期4 3 C4 10 0.234
药物A周期4 3 C3 11 0.937
药物A周期4 3 C3 12 0.980
药物A周期1 4 C3 1 1.220
药物A周期1 4 C4 1 0.182
药物A周期1 4 C3 2 0.983
药物A周期1 4 C4 2 0.132
药物A Cycl e 1 4 C3 3 0.979
药物A周期1 4 C4 3 0.128
药物A周期2 4 C3 4 1.190
药物A周期2 4 C4 4 0.134
药物A周期2 4 C3 5 1.010
药物A周期2 4 C4 5 0.076
药物A周期2 4 C3 6 1.100
药物A周期2 4 C4 6 0.083
药物A周期3 4 C3 7 1.140
药物A循环3 4 C4 7 0.108
药物A循环3 4 C3 8 1.140
药物A循环3 4 C4 8 0.104
药物A循环3 4 C3 9 1.120
药物A周期3 4 C4 9 0.080
;
跑;

proc sort data = immune out = sasuser.immune;
by pt;
跑;

现在图表的模板代码:

  proc模板; 
define statgraph gsv00251;
begingraph / designwidth = 7in designheight = 4.5in;
entrytitle'治疗的免疫学概况';
布局网格;
layout datalattice rowvar = lbparm /
headerlabeldisplay = value includemissingclass = false
columnaxisopts =(label =Cycle Daygriddisplay = on type = discrete
discreteopts =(tickdisplaylist =
(01530015300153001530))
offsetmin = .03 offsetmax = .03)
rowaxisopts =(offsetmax = .1 label =转换为SI单位的值
griddisplay = on)rowdatarange = union;
布局原型;
blockplot x = xval block = cyc / datatransparency = .75
display =(大纲填充)
name =blockfilltype = alternate;
seriesplot x = xval y = sival / group = pt index = pt name ='a'
display = all lineattrs =(pattern = 1 thickness = 2)
markerattrs =(symbol = circlefilled大小= 8);
endlayout;
endlayout;
条目'';
discretelegend'a'/ title ='Patient'across = 8;
endlayout;
endgraph;
end;
跑;

现在我想在每个块的顶部添加一些信息,所以我经历了一些在网络上搜索,我发现实现这个结果的最好方法是改变proc模板,添加2个格子行:具有这些信息的块状图,如图所示 https://support.sas.com/documentation/cdl/en/grstatug/62464/HTML/default/viewer.htm#n07sfa0fbx6yh5n1dyutt7boc3kp.htm (其中包含箱型统计和第二个示例) 。
$ b $ 2)第二个格子行包含之前发布的图。



所以我创建了这个原始样本数据集:

  data firstrow; 
长度ROW $ 20 TITLE $ 20 REASON $ 50 CHAR $ 20 VAR $ 20;
infile datalines dlm =',';
输入ROW TITLE原因CHAR VAR;
datalines;
行1,行1,第一行,第一行,第一行,$ b $行2,行2,第二行,第二行,第二行,$ b $行3,行3,第三理由,第三行,第三行,
行4,行4,第四行,第四行,第四行,
;
proc transpose data = firstrow out = firstrow_;
逐行;
var title reason char var;
跑;

并与以前的数据集合并(不可):

  proc sort data = immune out = immune; 
by pt;
跑;

数据免疫;
合并免疫firstrow_;
跑;

然后修改proc模板,添加 layout lattice 和块图。

  proc template; 
define statgraph gsv00251;
begingraph / designwidth = 7in designheight = 4.5in;
entrytitle'治疗的免疫学概况';

layout lattice / columns = 1 rowweights =(。15 .85);
blockplot x = row block = col1 / class = _name_
datatransparency = .75
display =(大纲填充值标签)
name =statsfilltype = alternate
valuehalign = center
includemissingclass = false
labelattrs = GraphDataText valueattrs = GraphDataText;
布局网格;
layout datalattice rowvar = lbparm /
headerlabeldisplay = value includemissingclass = false
columnaxisopts =(label =Cycle Daygriddisplay = on type = discrete
discreteopts =(tickdisplaylist =
(01530015300153001530))
offsetmin = .03 offsetmax = .03)
rowaxisopts =(offsetmax = .1 label =转换为SI单位的值
griddisplay = on)rowdatarange = union;
布局原型;
blockplot x = xval block = cyc / datatransparency = .75
display =(大纲填充)
name =blockfilltype = alternate;
seriesplot x = xval y = sival / group = pt index = pt name ='a'
display = all lineattrs =(pattern = 1 thickness = 2)
markerattrs =(symbol = circlefilled大小= 8);
endlayout;
endlayout;
条目'';
discretelegend'a'/ title ='Patient'across = 8;
endlayout;

endlayout;

endgraph;
end;
跑;

结果很好,但并非最不重要,我的意思是,列轴与两个图不一致,结果是发布的第一张图。

基本上有两个问题:右侧的标题标签和左侧的标签轴。 Howe可以改变这个情节,以获得正确的结果吗? (轴对齐)

由于我发布了很多代码,在这里您只能找到所有这些的最终版本

  data immune; 
格式sival f6.3;
输入trt $ 1-8 cyc $ 10-18 pt lbparm $ xval sival;
卡;
药物A周期1 1 C3 1 1.120
药物A周期1 1 C4 1 0.147
药物A周期1 1 C3 2 1.080
药物A周期1 1 C4 2 0.131
药物A周期1 1 C3 3 0.887
药物A周期1 1 C4 3 0.113
药物A周期2 1 C3 4 1.440
药物A周期2 1 C4 4 0.278
药物A周期2 1 C3 5 1.180
药物A周期2 1 C4 5 0.234
药物A周期2 1 C3 6 1.360
药物A周期2 1 C4 6 0.281
药物A周期3 1 C3 7 1.190
药物A周期3 1 C4 7 0.282
药物A周期3 1 C3 8 1.000
药物A周期3 1 C4 8 0.228
药物A周期3 1 C3 9 1.040
药物A循环3 1 C4 9 0.228
药物A循环4 1 C3 10 0.917
药物A循环4 1 C4 10 0.163
药物A循环4 1 C3 11 0.789
药物A周期4 1 C4 11 0.136
药物A周期4 1 C3 12 0.861
药物A周期4 1 C4 12 0.148
药物A周期1 2 C3 1 1.180
药物A周期1 2 C4 1 0.264
药物A周期1 2 C3 2 0.942
药物A周期1 2 C4 2 0.184
药物A周期1 2 C3 3 1.010
药物A周期1 2 C4 3 0.160
药物A周期2 2 C3 4 1.050
药物A周期2 2 C4 4 0.134
药物A周期2 2 C3 5 0.980
药物A周期2 2 C4 5 0.120
药物A周期2 2 C3 6 1.020
药物A周期2 2 C4 6 0.126
药物A周期3 2 C3 7 0.961
药物A周期3 2 C4 7 0.110
药物A周期3 2 C3 8 0.859
药物A周期3 2 C4 8 0.091
药物A周期3 2 C3 9 0.928
药物A周期3 2 C4 9 0.097
药物A周期4 2 C3 10 1.380
药物A周期4 2 C4 10 0.330
药物A周期4 2 C3 11 1.210
药物A周期4 2 C4 11 0.281
药物A周期4 2 C3 12 1.180
药物A周期4 2 C4 12 0.278
药物A周期1 3 C3 1 1.180
药物A周期1 3 C4 1 0.269
药物A周期1 3 C3 2 1.010
药物A周期1 3 C4 2 0.213
药物A周期1 3 C3 3 1.040
药物A周期1 3 C4 3 0.200
药物A周期2 3 C3 4 1.200
药物A周期2 3 C4 4 0.332
药物A周期2 3 C4 5 0.371
药物A周期2 3 C4 6 0.316
药物A周期3 3 C4 7 0.271
药物A周期3 3 C3 8 1.050
药物A周期3 3 C4 8 0.246
药物A周期3 3 C3 9 1.100
药物A周期3 3 C4 9 0.248
药物A周期4 3 C3 10 1.090
药物A周期4 3 C4 10 0.234
药物A周期4 3 C3 11 0.937
药物A周期4 3 C3 12 0.980
药物A周期1 4 C3 1 1.220
药物A周期1 4 C4 1 0.182
药物A周期1 4 C3 2 0.983
药物A周期1 4 C4 2 0.132
药物A Cycl e 1 4 C3 3 0.979
药物A周期1 4 C4 3 0.128
药物A周期2 4 C3 4 1.190
药物A周期2 4 C4 4 0.134
药物A周期2 4 C3 5 1.010
药物A周期2 4 C4 5 0.076
药物A周期2 4 C3 6 1.100
药物A周期2 4 C4 6 0.083
药物A周期3 4 C3 7 1.140
药物A循环3 4 C4 7 0.108
药物A循环3 4 C3 8 1.140
药物A循环3 4 C4 8 0.104
药物A循环3 4 C3 9 1.120
药物A周期3 4 C4 9 0.080
;
跑;


data firstrow;
长度ROW $ 20 TITLE $ 20 REASON $ 50 CHAR $ 20 VAR $ 20;
infile datalines dlm =',';
输入ROW TITLE原因CHAR VAR;
datalines;
行1,行1,第一行,第一行,第一行,$ b $行2,行2,第二行,第二行,第二行,$ b $行3,行3,第三理由,第三行,第三行,
行4,行4,第四行,第四行,第四行,
;

proc transpose data = firstrow out = firstrow_;
逐行;
var title reason char var;
跑;

proc sort data =豁免=免疫;
by pt;
跑;

数据免疫;
合并免疫firstrow_;
跑;

proc模板;
define statgraph gsv00251;
begingraph / designwidth = 7in designheight = 4.5in;
entrytitle'治疗的免疫学概况';

layout lattice / columns = 1 rowweights =(。15 .85);
columnaxes;
columnaxis / display =(ticks tickvalues);
endcolumnaxes;



blockplot x =行块= col1 / class = _name_
datatransparency = .75
display =(大纲填充值标签)
name =statsfilltype = alternate
valuehalign = center
includemissingclass = false
labelattrs = GraphDataText valueattrs = GraphDataText;
布局网格;
layout datalattice rowvar = lbparm /
headerlabeldisplay = value includemissingclass = false
columnaxisopts =(label =Cycle Daygriddisplay = on type = discrete
discreteopts =(tickdisplaylist =
(01530015300153001530))
offsetmin = .03 offsetmax = .03)
rowaxisopts =(offsetmax = .1 label =转换为SI单位的值
griddisplay = on)rowdatarange = union;
布局原型;
blockplot x = xval block = cyc / datatransparency = .75
display =(大纲填充)
name =blockfilltype = alternate;
seriesplot x = xval y = sival / group = pt index = pt name ='a'
display = all lineattrs =(pattern = 1 thickness = 2)
markerattrs =(symbol = circlefilled大小= 8);
endlayout;
endlayout;
条目'';
discretelegend'a'/ title ='Patient'across = 8;
endlayout;

endlayout;

endgraph;
end;
跑;
ods listing close;
ods html image_dpi = 100 file ='Immunology.html'path ='。';
ods graphics / reset noborder width = 600px height = 400px
imagename ='ClinicalHandout_Immunology'imagefmt = gif noscale;

proc sgrender data = immune template = gsv00251;
跑;
ods html close;
ods列表;


解决方案

来自sas社区中的交叉线程(谢谢,Sanjay) 。
https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/SAS-Graph-Align-axis-with-lattice-rows/mp/229696



当您为块图和DATAPANEL图使用具有单独单元格的外部LAYOUT LATTICE容器时,所包含的图的坐标轴之间没有对齐。这些图不相互了解。



面板中的BLOCKPLOT具有X = XVAL,而顶部的BLOCKPLOT具有X = ROW。这些是自变量。此外,顶部图形是独立的,并且不需要为下部分中的行标题保留空间。



最好的方法是避免使用数据面板。三行使用一个布局格。底部的两行将有'C3'和'C4'数据的系列图。您可以使用表达式仅提取一个LBPARM值的数据。使用INSET或ROWHWADER来放置类的值。顶行将使用块图或AxisTable进行统计。确保x变量相同或相似。



了解您使用的SAS版本非常有用。使用SAS 9.4M3更容易。


I'm really struggling myself with this problem, I really can't find a solution and I hope that, posting here, someone will help.

The problem is that with this 2-lattice-rows template I can't align the axis.

Now I detail everything I did with code to reproduce each step:

I have this plot

Here the code both for the graph and for the sample dataset (it's a simple version of this: http://support.sas.com/kb/39/092.html).

Sample dataset:

data immune;
   format sival f6.3;
   input trt $ 1-8 cyc $ 10-18 pt lbparm $ xval sival;
   cards;
Drug A   Cycle 1   1   C3  1   1.120
Drug A   Cycle 1   1   C4  1   0.147
Drug A   Cycle 1   1   C3  2   1.080
Drug A   Cycle 1   1   C4  2   0.131
Drug A   Cycle 1   1   C3  3   0.887
Drug A   Cycle 1   1   C4  3   0.113
Drug A   Cycle 2   1   C3  4   1.440
Drug A   Cycle 2   1   C4  4   0.278
Drug A   Cycle 2   1   C3  5   1.180
Drug A   Cycle 2   1   C4  5   0.234
Drug A   Cycle 2   1   C3  6   1.360
Drug A   Cycle 2   1   C4  6   0.281
Drug A   Cycle 3   1   C3  7   1.190
Drug A   Cycle 3   1   C4  7   0.282
Drug A   Cycle 3   1   C3  8   1.000
Drug A   Cycle 3   1   C4  8   0.228
Drug A   Cycle 3   1   C3  9   1.040
Drug A   Cycle 3   1   C4  9   0.228
Drug A   Cycle 4   1   C3 10   0.917
Drug A   Cycle 4   1   C4 10   0.163
Drug A   Cycle 4   1   C3 11   0.789
Drug A   Cycle 4   1   C4 11   0.136
Drug A   Cycle 4   1   C3 12   0.861
Drug A   Cycle 4   1   C4 12   0.148
Drug A   Cycle 1   2   C3  1   1.180
Drug A   Cycle 1   2   C4  1   0.264
Drug A   Cycle 1   2   C3  2   0.942
Drug A   Cycle 1   2   C4  2   0.184
Drug A   Cycle 1   2   C3  3   1.010
Drug A   Cycle 1   2   C4  3   0.160
Drug A   Cycle 2   2   C3  4   1.050
Drug A   Cycle 2   2   C4  4   0.134
Drug A   Cycle 2   2   C3  5   0.980
Drug A   Cycle 2   2   C4  5   0.120
Drug A   Cycle 2   2   C3  6   1.020
Drug A   Cycle 2   2   C4  6   0.126
Drug A   Cycle 3   2   C3  7   0.961
Drug A   Cycle 3   2   C4  7   0.110
Drug A   Cycle 3   2   C3  8   0.859
Drug A   Cycle 3   2   C4  8   0.091
Drug A   Cycle 3   2   C3  9   0.928
Drug A   Cycle 3   2   C4  9   0.097
Drug A   Cycle 4   2   C3 10   1.380
Drug A   Cycle 4   2   C4 10   0.330
Drug A   Cycle 4   2   C3 11   1.210
Drug A   Cycle 4   2   C4 11   0.281
Drug A   Cycle 4   2   C3 12   1.180
Drug A   Cycle 4   2   C4 12   0.278
Drug A   Cycle 1   3   C3  1   1.180
Drug A   Cycle 1   3   C4  1   0.269
Drug A   Cycle 1   3   C3  2   1.010
Drug A   Cycle 1   3   C4  2   0.213
Drug A   Cycle 1   3   C3  3   1.040
Drug A   Cycle 1   3   C4  3   0.200
Drug A   Cycle 2   3   C3  4   1.200
Drug A   Cycle 2   3   C4  4   0.332
Drug A   Cycle 2   3   C4  5   0.371
Drug A   Cycle 2   3   C4  6   0.316
Drug A   Cycle 3   3   C4  7   0.271
Drug A   Cycle 3   3   C3  8   1.050
Drug A   Cycle 3   3   C4  8   0.246
Drug A   Cycle 3   3   C3  9   1.100
Drug A   Cycle 3   3   C4  9   0.248
Drug A   Cycle 4   3   C3 10   1.090
Drug A   Cycle 4   3   C4 10   0.234
Drug A   Cycle 4   3   C3 11   0.937
Drug A   Cycle 4   3   C3 12   0.980
Drug A   Cycle 1   4   C3  1   1.220
Drug A   Cycle 1   4   C4  1   0.182
Drug A   Cycle 1   4   C3  2   0.983
Drug A   Cycle 1   4   C4  2   0.132
Drug A   Cycle 1   4   C3  3   0.979
Drug A   Cycle 1   4   C4  3   0.128
Drug A   Cycle 2   4   C3  4   1.190
Drug A   Cycle 2   4   C4  4   0.134
Drug A   Cycle 2   4   C3  5   1.010
Drug A   Cycle 2   4   C4  5   0.076
Drug A   Cycle 2   4   C3  6   1.100
Drug A   Cycle 2   4   C4  6   0.083
Drug A   Cycle 3   4   C3  7   1.140
Drug A   Cycle 3   4   C4  7   0.108
Drug A   Cycle 3   4   C3  8   1.140
Drug A   Cycle 3   4   C4  8   0.104
Drug A   Cycle 3   4   C3  9   1.120
Drug A   Cycle 3   4   C4  9   0.080
;
run;

proc sort data=immune out=sasuser.immune;
   by pt;
run;

Now the template code for the graph:

proc template;
  define statgraph gsv00251;
    begingraph / designwidth=7in designheight=4.5in;
      entrytitle 'Immunology Profile by Treatment';
      layout gridded;
        layout datalattice rowvar=lbparm /
               headerlabeldisplay=value includemissingclass=false
               columnaxisopts=(label="Cycle Day" griddisplay=on type=discrete
               discreteopts=(tickdisplaylist=
               ("0" "15" "30" "0" "15" "30" "0" "15" "30" "0" "15" "30"))  
               offsetmin = .03 offsetmax = .03)
               rowaxisopts=(offsetmax=.1 label="Values Converted to SI Units "
               griddisplay=on) rowdatarange=union;
        layout prototype;
          blockplot x=xval block=cyc / datatransparency = .75
                                       display=(outline fill ) 
                                       name="block" filltype=alternate;
          seriesplot x=xval y=sival / group=pt index=pt name='a'
                                      display=all lineattrs=(pattern=1 thickness=2) 
                                      markerattrs=(symbol=circlefilled size=8);    
        endlayout;
        endlayout;
        entry ' ';
        discretelegend 'a' / title='Patient' across=8;
      endlayout; 
    endgraph;
  end;
run;

Now I'd like to add some information on the top of each block, so I went through some searches on the web and I found out that the best way to achieve this result is to change the proc template, adding 2 lattice rows:

1) the first lattice row containing a blockplot with these informations like in this plot https://support.sas.com/documentation/cdl/en/grstatug/62464/HTML/default/viewer.htm#n07sfa0fbx6yh5n1dyutt7boc3kp.htm (the one with boxplots and statistics, the second example).

2) the second lattice row containing the previously posted plot.

So I created this raw sample dataset:

data firstrow;
length ROW $20 TITLE $20 REASON $50 CHAR $20 VAR $20;
infile datalines dlm=',';
input ROW TITLE REASON CHAR VAR;
datalines;
ROW 1,ROW 1,FIRST REASON,FIRST ROW,FIRST VAR,
ROW 2,ROW 2,SECOND REASON,SECOND ROW,SECOND VAR,
ROW 3,ROW 3,THIRD REASON,THIRD ROW,THIRD VAR,
ROW 4,ROW 4,FOURTH REASON,FOURTH ROW,FOURTH VAR,
;
proc transpose data=firstrow out=firstrow_;
by row;
var title reason char var;
run;

and merged (no by) it with the previous dataset:

proc sort data=immune out=immune;
   by pt;
run;

data immune;
merge immune firstrow_;
run;

then modified the proc template adding layout lattice and the blockplot.

proc template;
  define statgraph gsv00251;
    begingraph / designwidth=7in designheight=4.5in;
      entrytitle 'Immunology Profile by Treatment';

     layout lattice / columns=1 rowweights=(.15 .85);
              blockplot x=row block=col1  / class=_name_
                        datatransparency = .75
                        display=(outline fill values label)
                        name="stats" filltype=alternate 
                        valuehalign=center
                        includemissingclass=false
                        labelattrs=GraphDataText valueattrs=GraphDataText ;
      layout gridded;
        layout datalattice rowvar=lbparm /
               headerlabeldisplay=value includemissingclass=false
               columnaxisopts=(label="Cycle Day" griddisplay=on type=discrete
               discreteopts=(tickdisplaylist=
               ("0" "15" "30" "0" "15" "30" "0" "15" "30" "0" "15" "30"))  
               offsetmin = .03 offsetmax = .03)
               rowaxisopts=(offsetmax=.1 label="Values Converted to SI Units "
               griddisplay=on) rowdatarange=union;
        layout prototype;
          blockplot x=xval block=cyc / datatransparency = .75
                                       display=(outline fill ) 
                                       name="block" filltype=alternate;
          seriesplot x=xval y=sival / group=pt index=pt name='a'
                                      display=all lineattrs=(pattern=1 thickness=2) 
                                      markerattrs=(symbol=circlefilled size=8);    
        endlayout;
        endlayout;
        entry ' ';
        discretelegend 'a' / title='Patient' across=8;
      endlayout; 

    endlayout;

    endgraph;
  end;
run;

The result is good but not least, I mean, the column axis is not aligned with the two plots, the result is the first plot posted.

There are basically 2 issues: header labels on the right and axis label on the left. Howe can I change this plot, to gain the correct result? (axis aligned)

Since I posted a lot of code, here you will find only the final version of all this

 data immune;
   format sival f6.3;
   input trt $ 1-8 cyc $ 10-18 pt lbparm $ xval sival;
   cards;
Drug A   Cycle 1   1   C3  1   1.120
Drug A   Cycle 1   1   C4  1   0.147
Drug A   Cycle 1   1   C3  2   1.080
Drug A   Cycle 1   1   C4  2   0.131
Drug A   Cycle 1   1   C3  3   0.887
Drug A   Cycle 1   1   C4  3   0.113
Drug A   Cycle 2   1   C3  4   1.440
Drug A   Cycle 2   1   C4  4   0.278
Drug A   Cycle 2   1   C3  5   1.180
Drug A   Cycle 2   1   C4  5   0.234
Drug A   Cycle 2   1   C3  6   1.360
Drug A   Cycle 2   1   C4  6   0.281
Drug A   Cycle 3   1   C3  7   1.190
Drug A   Cycle 3   1   C4  7   0.282
Drug A   Cycle 3   1   C3  8   1.000
Drug A   Cycle 3   1   C4  8   0.228
Drug A   Cycle 3   1   C3  9   1.040
Drug A   Cycle 3   1   C4  9   0.228
Drug A   Cycle 4   1   C3 10   0.917
Drug A   Cycle 4   1   C4 10   0.163
Drug A   Cycle 4   1   C3 11   0.789
Drug A   Cycle 4   1   C4 11   0.136
Drug A   Cycle 4   1   C3 12   0.861
Drug A   Cycle 4   1   C4 12   0.148
Drug A   Cycle 1   2   C3  1   1.180
Drug A   Cycle 1   2   C4  1   0.264
Drug A   Cycle 1   2   C3  2   0.942
Drug A   Cycle 1   2   C4  2   0.184
Drug A   Cycle 1   2   C3  3   1.010
Drug A   Cycle 1   2   C4  3   0.160
Drug A   Cycle 2   2   C3  4   1.050
Drug A   Cycle 2   2   C4  4   0.134
Drug A   Cycle 2   2   C3  5   0.980
Drug A   Cycle 2   2   C4  5   0.120
Drug A   Cycle 2   2   C3  6   1.020
Drug A   Cycle 2   2   C4  6   0.126
Drug A   Cycle 3   2   C3  7   0.961
Drug A   Cycle 3   2   C4  7   0.110
Drug A   Cycle 3   2   C3  8   0.859
Drug A   Cycle 3   2   C4  8   0.091
Drug A   Cycle 3   2   C3  9   0.928
Drug A   Cycle 3   2   C4  9   0.097
Drug A   Cycle 4   2   C3 10   1.380
Drug A   Cycle 4   2   C4 10   0.330
Drug A   Cycle 4   2   C3 11   1.210
Drug A   Cycle 4   2   C4 11   0.281
Drug A   Cycle 4   2   C3 12   1.180
Drug A   Cycle 4   2   C4 12   0.278
Drug A   Cycle 1   3   C3  1   1.180
Drug A   Cycle 1   3   C4  1   0.269
Drug A   Cycle 1   3   C3  2   1.010
Drug A   Cycle 1   3   C4  2   0.213
Drug A   Cycle 1   3   C3  3   1.040
Drug A   Cycle 1   3   C4  3   0.200
Drug A   Cycle 2   3   C3  4   1.200
Drug A   Cycle 2   3   C4  4   0.332
Drug A   Cycle 2   3   C4  5   0.371
Drug A   Cycle 2   3   C4  6   0.316
Drug A   Cycle 3   3   C4  7   0.271
Drug A   Cycle 3   3   C3  8   1.050
Drug A   Cycle 3   3   C4  8   0.246
Drug A   Cycle 3   3   C3  9   1.100
Drug A   Cycle 3   3   C4  9   0.248
Drug A   Cycle 4   3   C3 10   1.090
Drug A   Cycle 4   3   C4 10   0.234
Drug A   Cycle 4   3   C3 11   0.937
Drug A   Cycle 4   3   C3 12   0.980
Drug A   Cycle 1   4   C3  1   1.220
Drug A   Cycle 1   4   C4  1   0.182
Drug A   Cycle 1   4   C3  2   0.983
Drug A   Cycle 1   4   C4  2   0.132
Drug A   Cycle 1   4   C3  3   0.979
Drug A   Cycle 1   4   C4  3   0.128
Drug A   Cycle 2   4   C3  4   1.190
Drug A   Cycle 2   4   C4  4   0.134
Drug A   Cycle 2   4   C3  5   1.010
Drug A   Cycle 2   4   C4  5   0.076
Drug A   Cycle 2   4   C3  6   1.100
Drug A   Cycle 2   4   C4  6   0.083
Drug A   Cycle 3   4   C3  7   1.140
Drug A   Cycle 3   4   C4  7   0.108
Drug A   Cycle 3   4   C3  8   1.140
Drug A   Cycle 3   4   C4  8   0.104
Drug A   Cycle 3   4   C3  9   1.120
Drug A   Cycle 3   4   C4  9   0.080
;
run;


data firstrow;
length ROW $20 TITLE $20 REASON $50 CHAR $20 VAR $20;
infile datalines dlm=',';
input ROW TITLE REASON CHAR VAR;
datalines;
ROW 1,ROW 1,FIRST REASON,FIRST ROW,FIRST VAR,
ROW 2,ROW 2,SECOND REASON,SECOND ROW,SECOND VAR,
ROW 3,ROW 3,THIRD REASON,THIRD ROW,THIRD VAR,
ROW 4,ROW 4,FOURTH REASON,FOURTH ROW,FOURTH VAR,
;

proc transpose data=firstrow out=firstrow_;
by row;
var title reason char var;
run;

proc sort data=immune out=immune;
   by pt;
run;

data immune;
merge immune firstrow_;
run;

proc template;
  define statgraph gsv00251;
    begingraph / designwidth=7in designheight=4.5in;
      entrytitle 'Immunology Profile by Treatment';

     layout lattice / columns=1 rowweights=(.15 .85);
                columnaxes;
                    columnaxis / display=(ticks tickvalues);
                endcolumnaxes;



              blockplot x=row block=col1  / class=_name_
                        datatransparency = .75
                        display=(outline fill values label)
                        name="stats" filltype=alternate 
                        valuehalign=center
                        includemissingclass=false
                        labelattrs=GraphDataText valueattrs=GraphDataText ;
      layout gridded;
        layout datalattice rowvar=lbparm /
               headerlabeldisplay=value includemissingclass=false
               columnaxisopts=(label="Cycle Day" griddisplay=on type=discrete
               discreteopts=(tickdisplaylist=
               ("0" "15" "30" "0" "15" "30" "0" "15" "30" "0" "15" "30"))  
               offsetmin = .03 offsetmax = .03)
               rowaxisopts=(offsetmax=.1 label="Values Converted to SI Units "
               griddisplay=on) rowdatarange=union;
        layout prototype;
          blockplot x=xval block=cyc / datatransparency = .75
                                       display=(outline fill ) 
                                       name="block" filltype=alternate;
          seriesplot x=xval y=sival / group=pt index=pt name='a'
                                      display=all lineattrs=(pattern=1 thickness=2) 
                                      markerattrs=(symbol=circlefilled size=8);    
        endlayout;
        endlayout;
        entry ' ';
        discretelegend 'a' / title='Patient' across=8;
      endlayout; 

    endlayout;

    endgraph;
  end;
run;
ods listing close;
ods html image_dpi=100 file='Immunology.html' path='.';
ods graphics / reset noborder width=600px height=400px 
  imagename='ClinicalHandout_Immunology' imagefmt=gif noscale;

proc sgrender data=immune template=gsv00251; 
run;
ods html close;
ods listing;

解决方案

from crossposted thread in sas community (Thanks, Sanjay). https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/SAS-Graph-Align-axis-with-lattice-rows/m-p/229696

When you use an outer LAYOUT LATTICE container with separate cells for the block plot and the DATAPANEL graph, there is no alignment between the axes of the contained plots. The plots do not know about each other.

The BLOCKPLOT in the panel has X=XVAL while the BLOCKPLOT at the top has X=ROW. These are independent variables. Also, the top graph is stand alone, and does not have need for reserving space for the row headers in the lower section.

The best way to do this is to avoid using the data panel. Use one LAYOUT LATTICE with three rows. Bottom two rows will have the series plots for 'C3' and 'C4' data. You can use expressions to pull out only data for one value of LBPARM. Use INSET or ROWHWADER to place the class value. Top row will have the statistics using a block plot or AxisTable. make sure the x variables are same or similar.

It is useful to know what release of SAS you are using. Will be easier with SAS 9.4M3.

这篇关于SAS图形:将2个图的轴与格子排对齐的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆