BookmarkSubscribeRSS Feed
DGrint
Obsidian | Level 7

Hello,

 

I have defined my own legend with KEYLEGEND in SGPlot. The legend only includes 2 values which are labelled 'Sensitivity' and 'Specificity'. However, in the output the labels are truncated to 'Sensitivit...' and 'Specificit...'. There is plenty of room in the plot area to fit the additional letter 'y'.

 

Is there any way to increase the default label length?

 

Thanks,

 

Daniel

8 REPLIES 8
RW9
Diamond | Level 26 RW9
Diamond | Level 26

How have you defined them.  What I think you have there is what happens when you don't specify a length for a varaible, it then defaults to 8 characters long.  You may need to put a length statement somewhere, but would need to see the code.

DGrint
Obsidian | Level 7

The labels are defined within SGPlot. Code below

 

proc sgplot data=table nowall noborder noautolegend dattrmap=attrmap;
styleattrs axisextent=data;
scatter y=y_val x=sen / markerattrs=(symbol=squarefilled size=4 color=cx2A25D9) name='sens' legendlabel="Sensitivity";

scatter y=y_val x=spec / markerattrs=(symbol=diamondfilled size=4 color=cxB2182B) name='spec' legendlabel="Specificity";

xaxis values=(0 to 100 by 10) label="Sensitivity/Specificity (%)";
yaxis reverse display=none;

keylegend 'sens' 'spec' / position=top location=inside across=2 noborder;

run;

Cynthia_sas
SAS Super FREQ

Hi:

  Using SASHELP.CLASS and your code technique slightly changed to put move the legend so it didn't collide with the data points, I still get the labels correctly (not truncated) in 9.4M3:

 

keylegend2.png

 

 

Cynthia

DGrint
Obsidian | Level 7

Playing around with sashelp.class I've figured it out now. Silly error on my part. I had specified a large image size and high dpi. It appears that Java had run out of memory rendering the image and omitted the final letters of the legend.

 

Oops!

 

Thanks very much for your help!

Cynthia_sas
SAS Super FREQ

Hi:

  This might be something you want to raise with Tech Support so they can look at all your code and your data. In version 9.4M3, this is what I get:

keylegend.png

 

I used 2 different techniques for #1 and #2. #3 was just testing a really, really long value for the variable.

 

Here's the code I used:

**Approach 1: Use a format for the labels';
proc format;
  value $genf 'M' = 'Specificity'
              'F' = 'Sensitivity';
run;

proc sgplot data=sashelp.class;
  scatter x=height y=weight / group=sex;
  keylegend /title='1 this is the long label';
  format sex $genf.;
run;

** Approach 2: make a new character variable with long length;
data newclass;
  length type $12;
  set sashelp.class;
  if sex = 'F' then type = 'Sensitivity';
  else type = 'Specificity';
run;

proc sgplot data=newclass;
  scatter x=height y=weight / group=type;
  keylegend /title='2 this is the long label';
run;

** Approach 3: try really silly length;
data newclass2;
  length type $35;
  set sashelp.class;
  if sex = 'F' then type = 'Supercalifragilisticexpealidocious';
  else type = 'Antidisestablishmentarianism';
run;

proc sgplot data=newclass2;
  scatter x=height y=weight / group=type;
  keylegend /title='3 this is the long label';
run;
 

 

If you run my code and get different results, I would recommend opening a track with Tech Support.

 

Cynthia

 

DGrint
Obsidian | Level 7

Thanks for the suggestions. However, I am defining the labels within SGPlot as there are other elements I don't want to include in the legend. Full code below.

 

proc sgplot data=table nowall noborder noautolegend dattrmap=attrmap;
styleattrs axisextent=data;
scatter y=y_val x=sen / markerattrs=(symbol=squarefilled size=5 color=cx2A25D9) name='sens' legendlabel="Sensitivity";
highlow y=y_val low=sen_l high=sen_u / lineattrs=(color=cx2A25D9 pattern=1) highcap=serif lowcap=serif transparency=0.6;

scatter y=y_val x=spec / markerattrs=(symbol=diamondfilled size=5 color=cxB2182B) name='spec' legendlabel="Specificity";
highlow y=y_val low=spec_l high=spec_u / lineattrs=(color=cxB2182B pattern=1) highcap=serif lowcap=serif transparency=0.6;

yaxistable diag / valuejustify=left label labeljustify=left location=inside position=left labelattrs=(size=10pt weight=bold) textgroup=ind textgroupid=text;
yaxistable area / label location=inside position=left labelattrs=(size=10pt weight=bold) textgroup=ind1 textgroupid=text;

xaxis values=(0 to 100 by 10) label="Sensitivity/Specificity (%)";
yaxis reverse display=none;

keylegend 'sens' 'spec' / position=top location=inside across=2 noborder;

run;

 

Can you think of anything else, given this method, before I go to tech support? It doesn't seem to matter what labels I specify. If I shorten them to 'Sensit' and 'Specif' then the output says 'Sensi...' and 'Speci...'.

ballardw
Super User

Can you provide example data to test your code against? Or modify the code to run against one of the SAS supplied data sets in SASHELP?

Cynthia_sas
SAS Super FREQ

Hi:

  Can you try running this code:


proc sgplot data=sashelp.class nowall noborder noautolegend  ;
scatter y=age x=height / markerattrs=(symbol=squarefilled size=4 color=cx2A25D9) 
        name='sens' legendlabel="Sensitivity";
scatter y=age x=weight / markerattrs=(symbol=diamondfilled size=4 color=cxB2182B) 
        name='spec' legendlabel="Specificity";
xaxis values=(0 to 100 by 10) label="Sensitivity/Specificity (%)";
yaxis reverse display=none;
keylegend 'sens' 'spec' / position=bottomleft location=inside across=2  ;
run;

When I run this code, I get these results:

keylegend3.png

 

So I am not observing what you report. I used SASHELP.CLASS and moved the legend so as not to collide with the data points.

 

If you get truncated labels when you try my code, then I recommend working with Tech Support.

 

Cynthia

sas-innovate-2024.png

Join us for SAS Innovate April 16-19 at the Aria in Las Vegas. Bring the team and save big with our group pricing for a limited time only.

Pre-conference courses and tutorials are filling up fast and are always a sellout. Register today to reserve your seat.

 

Register now!

How to Concatenate Values

Learn how use the CAT functions in SAS to join values from multiple variables into a single value.

Find more tutorials on the SAS Users YouTube channel.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 8 replies
  • 4151 views
  • 1 like
  • 4 in conversation