简体   繁体   English

SAS - 可以使用注释在同一 position 中显示文本,无论图例的大小和图形的大小是多少?

[英]SAS - Possible to display text using annotate at the same position whithin the graph whichever the size of legend and size of graph?

In SAS, I'm trying to set a 'fixed' position of an arrow to be displayed on a graph.在 SAS 中,我试图设置要在图表上显示的箭头的“固定”position。 I would like the arrow to be always displayed at the same position, whichever the size of the graph.我希望箭头始终显示在相同的 position 上,无论图形大小。 For now, I'm using annotate to display the arrow, its coordinates x1 and y1 expressed as a percentage of the graph area (DRAWSPACE='GRAPHPERCENT').现在,我使用annotate 来显示箭头,它的坐标x1 和y1 表示为图形区域的百分比(DRAWSPACE='GRAPHPERCENT')。 Below is my code to generate the graph, and the annotate dataset:下面是我生成图形的代码和注释数据集:

DATA anno_test;
    length function $10 label $20;
    retain y1 15 drawspace 'GRAPHPERCENT';
    function='ARROW';x1=15;x2=10;y2=15;linethickness=1;shape="FILLED";OUTPUT;
    function='ARROW';x1=93;x2=98;y2=15;linethickness=1;shape="FILLED";OUTPUT;
RUN;

ODS GRAPHICS ON BORDER=OFF;
PROC SGPLOT DATA=_cumul sganno=anno_test NOBORDER;
    STYLEATTRS DATALINEPATTERNS=(1 15 2 8 4 41);
    STEP X=score Y=cum_pct/GROUP=newgroup lineattrs=(thickness=1.5);
    YAXIS LABEL="Cumulative percentage of subjects" VALUES=(0 TO 100 BY 10) VALUEATTRS=(Size=9pt) LABELATTRS=(Size=10pt Weight=bold);
    XAXIS LABEL="Score" VALUES=(-60 TO 60 BY 20) VALUEATTRS=(Size=9pt) LABELATTRS=(Size=10pt Weight=bold);
    KEYLEGEND / TITLE=" " NOBORDER VALUEATTRS=(Size=7);
    REFLINE 0 / AXIS=X LINEATTRS=(Pattern=34 Thickness=0.6);
    REFLINE 50 / AXIS=Y LINEATTRS=(Pattern=34 Thickness=0.6);
RUN;
ODS GRAPHICS OFF;

The issue I have is that, depending on the size of the legend and the size of the graph, the arrow can overlapped the x-axis.我遇到的问题是,根据图例的大小和图表的大小,箭头可以与 x 轴重叠。 I'm not familiar with the annotate, but I tried different options and drawspace but I cann't display it perfectly regardless of the size of the legend.我不熟悉注释,但我尝试了不同的选项和绘图空间,但无论图例的大小如何,我都无法完美地显示它。

Does anyone have an idea?有人有想法吗? Or should I locked the size of the graph to avoid this "issue"?或者我应该锁定图表的大小以避免这个“问题”? Thanks!谢谢!

Try using DATAPERCENT尝试使用DATAPERCENT

data have;
  call streaminit(2020);
  do score = -50 to 50 by 5;
    z = 100;
    do newgroup = 'A', 'B', 'C';
      cum_pct = rand('integer',floor(z/2),z);
      output;
      z = z - cum_pct;
    end;
    newgroup = 'D';
    cum_pct = z;
    output;
  end;
run;

DATA anno_test;
    length function $10 label $20;
    retain y1 15 DRAWSPACE 'DATAPERCENT';
    function='ARROW';x1=10;x2=  0;y2=15;linethickness=1;shape="FILLED";OUTPUT;
    function='ARROW';x1=90;x2=100;y2=15;linethickness=1;shape="FILLED";OUTPUT;
RUN;

Arrows pointing to edge of data area指向数据区域边缘的箭头

在此处输入图像描述

Same arrows when data area is a wider X axis当数据区域是更宽的 X 轴时,相同的箭头

在此处输入图像描述

Same arrows when annotation y values are y1 = -10; y2 = -10;当注释 y 值为y1 = -10; y2 = -10; y1 = -10; y2 = -10;

在此处输入图像描述

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM