如何旋转 SAS SGPLOT 图中的 x 轴标签,使其垂直(与 x 轴成 90 度) [英] How do I rotate the x-axis labels in a SAS SGPLOT graph so that they are perpendicular (at 90 degrees to x-axis)

查看:34
本文介绍了如何旋转 SAS SGPLOT 图中的 x 轴标签,使其垂直(与 x 轴成 90 度)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以旋转 SAS SGPLOT 中的 x 轴标签,使其垂直(与 x 轴成 90 度)?fitpolicy 选项旋转 45 度,但这并不是我所需要的.

SAS 代码:

ods pdf 样式 = 自定义文件='';proc sgplot 数据 = 文件名;系列 x = 日期 y = 失业率_15_24/lineattrs =(颜色 = CX963634 厚度 = 2 图案=实心);系列 x = 日期 y = 失业率_15_/lineattrs =(颜色 = CX538DD5 厚度 = 2 图案=实心);xaxis type=time fitpolicy=rotatethin notimesplit interval=year offsetmax=0 label = ' ' values = ("28FEB1995"d to "28FEB2015"d by year);yaxis label = ' ' values = (0 to 18 by 2);x2axis display=(nolabel novalues);keylegend/location = inside position = topright;label失业率_15_24 =青年(15-24岁)失业率";标签失业率_15_ =总体(15年以上)失业率";跑;ods pdf 关闭;

我也尝试在 SAS 中使用图形模板语言.下面是用 GTL 编写的等价代码:

proc 模板;定义 statgraph mysgplot;开始图;布局叠加/循环属性=真xaxisopts =(标记="offsetmax = 0类型=时间timeopts =(tickvaluelist =(12842 13207 13573 13938 14303 14668 15034 15399 15764 16129 16495 16860 17225 17590 17956 18321 18686 19051 19417 19782 20147)viewmin = 12842 viewmax = 20147 tickvaluefitpolicy = rotatethinsplittickvalue=false 间隔=年))yaxisopts=(label="" type=linear linearopts=(tickvaluelist=(0 2 4 6 8 10 12 14 16 18) viewmin=0 viewmax=18 ))x2axisopts=(显示=(刻度线)类型=自动);seriesplot x='date'n y='unemployment_rate_15_24'n/primary=true lineattrs=(color=cx963634 pattern=1粗细=2) legendlabel="青年(15-24岁)失业率" NAME="SERIES";seriesplot x='date'n y='unemployment_rate_15_'n/lineattrs=(color=cx538dd5 pattern=1粗细=2) legendlabel="总体(15年以上)失业率" NAME="SERIES1";离散传奇系列"系列1"/位置=内部对齐=右对齐=顶部;端布局;端图;结尾;跑;proc sgrender 数据=文件名模板=mysgplot;跑;

解决方案

我不相信在 SGPLOT 中不使用注释就可以做到这一点.他们有一段很好的代码可以使用注释here..p>

在 GTL 中,他们在 9.4 中引入了 TICKVALUEROTATION,它需要与 TICKVALUEFITPOLICY=ROTATE|ROTATEALWAYSSPLITTICKVALUE=FALSE 一起使用.看到这个:

数据测试数据;调用streaminit(7);做 timevar = 12900 到 16900 乘 500;年龄=10+rand('正常',5,2);输出;结尾;格式化 timevar date9.;跑;过程模板;定义 statgraph mysgplot;开始图;布局叠加/循环属性=真xaxisopts=(label="" offsetmax=0 type=timetimeopts=(tickvaluerotation=VERTICAL TICKVALUEFITPOLICY=rotatealways splittickvalue=false))yaxisopts=(label="" type=linear linearopts=(tickvaluelist=(0 2 4 6 8 10 12 14 16 18) viewmin=0 viewmax=18 ))x2axisopts=(显示=(刻度线)类型=自动);seriesplot x=timevar y=age/lineattrs=(color=cx538dd5 pattern=1粗细=2)legendlabel="总体(15+年)失业率"NAME="SERIES1";离散传奇系列"系列1"/位置=内部对齐=右对齐=顶部;端布局;端图;结尾;跑;proc sgrender 数据 = testdata 模板 = mysgplot;跑;

我稍微简化了您的轴以确保它正常工作,但我认为您的大多数轴语句都可以.

在 9.3 或更早版本中,我认为您会遇到注释或 45 度问题.或者看看您是否可以说服 SCATTERPLOT 在轴之外绘制.或者也许使用 SERIESPLOT 和 SCATTERPLOT 来绘制自己的轴,但这似乎有点过头了.

上面的代码如下所示:

Is it possible to rotate the x-axis labels in SAS SGPLOT so that they are perpendicular (at 90 degrees to x-axis)? The fitpolicy option rotates 45 degrees, but this is not exactly what I need.

SAS code:

ods pdf style = custom file='';
proc sgplot data = filename;
series x = date y = unemployment_rate_15_24 / lineattrs = (color = CX963634 thickness = 2 pattern=solid);
series x = date y = unemployment_rate_15_ / lineattrs = (color = CX538DD5 thickness = 2 pattern=solid);
xaxis type=time fitpolicy=rotatethin notimesplit interval=year offsetmax=0 label = ' ' values = ("28FEB1995"d to "28FEB2015"d by year);
yaxis label = ' ' values = (0 to 18 by 2);
x2axis display=(nolabel novalues);
keylegend / location = inside position = topright;
label unemployment_rate_15_24 = "Youth (15-24 years) unemployment rate";
label unemployment_rate_15_ = "Overall (15+ years) unemployment rate";
run;
ods pdf close;

I've also tried to use the Graph Template Language in SAS. Here's the equiavalent code written in GTL:

proc template;
define statgraph mysgplot;
begingraph;
layout overlay /
cycleattrs=true 
xaxisopts=(label=" " offsetmax=0 type=time timeopts=(tickvaluelist=(12842 13207 13573 13938 14303 14668 15034 15399 15764 16129 16495 16860 17225 17590 17956 18321 18686 19051 19417 19782 20147) viewmin=12842 viewmax=20147 tickvaluefitpolicy=rotatethin splittickvalue=false interval=year)) 
yaxisopts=(label=" " type=linear linearopts=(tickvaluelist=(0 2 4 6 8 10 12 14 16 18) viewmin=0 viewmax=18 )) 
x2axisopts=(display=(ticks line) type=auto);
seriesplot x='date'n y='unemployment_rate_15_24'n / primary=true lineattrs=( color=cx963634 pattern=1 thickness=2) legendlabel="Youth (15-24 years) unemployment rate" NAME="SERIES";
seriesplot x='date'n y='unemployment_rate_15_'n / lineattrs=( color=cx538dd5 pattern=1 thickness=2) legendlabel="Overall (15+ years) unemployment rate" NAME="SERIES1";
discretelegend "SERIES" "SERIES1" / location=inside halign=right valign=top;
endlayout;
endgraph;
end;
run;

proc sgrender data = filename template=mysgplot;
run;

解决方案

I don't believe that it's possible to do that in SGPLOT without using annotation. They have a nice piece of code for doing that with annotation here.

With GTL, in 9.4 they introduce TICKVALUEROTATION, which needs to be used in tandem with TICKVALUEFITPOLICY=ROTATE|ROTATEALWAYS and SPLITTICKVALUE=FALSE. See this:

data testdata;
  call streaminit(7);
  do timevar = 12900 to 16900 by 500;
    age=10+rand('Normal',5,2);
    output;
  end;
  format timevar date9.;
run;

proc template;
define statgraph mysgplot;
begingraph;
layout overlay /
cycleattrs=true 
xaxisopts=(label=" " offsetmax=0 type=time 
    timeopts=(tickvaluerotation=VERTICAL TICKVALUEFITPOLICY=rotatealways splittickvalue=false) )
yaxisopts=(label=" " type=linear linearopts=(tickvaluelist=(0 2 4 6 8 10 12 14 16 18) viewmin=0 viewmax=18 )) 
x2axisopts=(display=(ticks line) type=auto);
seriesplot x=timevar y=age
    / lineattrs=( color=cx538dd5 pattern=1 thickness=2) legendlabel="Overall (15+ years) unemployment rate" NAME="SERIES1";
discretelegend "SERIES" "SERIES1" / location=inside halign=right valign=top;
endlayout;
endgraph;
end;
run;

proc sgrender data = testdata template=mysgplot;
run;

I slightly simplify your axis to make sure it works properly, but I think most of your axis statements are okay.

In 9.3 or earlier, I think you're stuck with annotation or 45 degrees. Or seeing if you can convince a SCATTERPLOT to draw outside of the axes. Or perhaps using a SERIESPLOT and a SCATTERPLOT to draw your own axes, but that seems a bit over the top.

Here's what the above code looks like:

这篇关于如何旋转 SAS SGPLOT 图中的 x 轴标签,使其垂直(与 x 轴成 90 度)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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