BookmarkSubscribeRSS Feed
Jennys
Calcite | Level 5
Hello

I have a linegraph where the labels for each line is long. If the legend contains a lot of explanation text for the lines, the text overlaps. If I change the x- and ypixels, the graph gets bigger and the text in the legend get supersmall.

Is there a way to tell graph that the graph itself should be x*y pixels big and the rest should be left to the legend? So the text won´t be resized.


br
jenny
8 REPLIES 8
GraphGuy
Meteorite | Level 14
What proc are you using? (proc gplot?)
What output device are you using? (device=gif? java? activex? other?)
Are you specifying any "goptions htext" size? or gunit=pct, etc?
And are you doing anything "tricky" such as using "proc greplay"?

The sizing of the legends, and other text can depend on several things.
Jennys
Calcite | Level 5
Hello

I run a proc gplot with no tricky things except the legend.

legend1
label = none
position =(bottom center)
value = (&longvalues);

Theese are the goptions I have:

goptions ftext=Verdana htext=0.5 device = javaimg colors=("#008040" "#99CCFF" "#99FFFF" "#66FF66");

br
Jenny
GraphGuy
Meteorite | Level 14
Hmm ... the dev=javaimg is a likely candidate ... it might only have "partial support" of the SAS/Graph options that control the legend size.

If you want the most complete control of everything in the graph (such as the legend text size), I'd recommend using device=png (or device=gif). Also, I'd recommend specifying a specific point-size for the text, such as ...

goptions htext=10pt;

Or, if you want the legend to be a specific size, different from the rest of the text, you can control that via a legend statement, something like ...

legend1 value=(height=10pt);
Jennys
Calcite | Level 5
Here is an example that illustrates my problem:
If I change the array to 10 items, it looks ok. But with 18 the text get too small.
If I change the ypixels to 1000 the graph gets bigger but not the legend.

goptions dev =javaimg xpixels=640 ypixels=480;
data fmt;
fmtname = '$ATCFMT';
length label $160;
start="0 ";end= "0 ";label="saknas ";output;
start="A ";end= "A ";label="MATSMALTNINGSORGAN OCH AMNESOMSATTNING ";output;
start="B ";end= "B ";label="BLOD OCH BLODBILDANDE ORGAN ";output;
start="C ";end= "C ";label="HJARTA OCH KRETSLOPP ";output;
start="D ";end= "D ";label="HUD ";output;
start="G ";end= "G ";label="URIN- OCH KONSORGAN SAMT KONSHORMONER ";output;
start="H ";end= "H ";label="HORMONER EXKL KONSHORMONER ";output;
start="J ";end= "J ";label="INFEKTIONSSJUKDOMAR ";output;
start="L ";end= "L ";label="TUMORER OCH RUBBNINGAR I IMMUNSYSTEMET ";output;
start="M ";end= "M ";label="RORELSEAPPARATEN ";output;
start="N ";end= "N ";label="NERVSYSTEMET ";output;
start="P ";end= "P ";label="ANTIPARASITARA, INSEKTSDODANDE OCH REPEL ";output;
start="Q ";end= "Q ";label="gentamycin,betametazon,klotrimazol ";output;
start="R ";end= "R ";label="ANDNINGSORGANEN ";output;
start="S ";end= "S ";label="OGON OCH ORON ";output;
start="T ";end= "T ";label="DIALYSVAROR (ASF) ";output;
start="U ";end= "U ";label="ISOTOPER (ASF) ";output;
start="V ";end= "V ";label="VARIA ";output;
start="W ";end= "W ";label="TILLFALLIGA HANDELSVAROR ";output;
start="X ";end= "X ";label="HANDELSVAROR ";output;
start="Y ";end= "Y ";label="FORBRUKNINGSARTIKLAR ";output;
start="Z ";end= "Z ";label="TILLBEHOR ";output;
run;

data b;
set fmt;
start = compress(start);
end = compress(end);
label = strip(label);
run;

proc format cntlin = b;
run;

data test(keep = sex2 value height);
set sashelp.class;
length sex2 $160;
array kon (18) $ ('A','B','C','D','E','F','G','H','I','J','K' 'L' 'M' 'N' 'O' 'P' 'Q' 'R');
do i = 1 to dim(kon);
sex2 = propcase(put(kon(i),$ATCFMT.));
value = ranuni(0);
output;
end;
run;


proc sort data = test;
by value;
run;

proc sql noprint;
select distinct(quote(strip(sex2))) into: longvalues separated ' '
from test;
quit;



legend1
label = none
position =(bottom center)
across = 1
value = (h=1 &longvalues)
;

proc gplot data = test;
plot height*value=sex2 /
legend = legend1
cframe=cxFFFFFF

;

run;
GraphGuy
Meteorite | Level 14
I've downloaded/saved your sample, and experimented a little in v9.2, and confirmed that the legend & legend text just "do not work well" with dev=javaimg.

If you use dev=png (rather than dev=javaimg), and the following options, it works fine (ie, the legend & graph resize as needed, and "play well together"):

goptions dev=png xpixels=640 ypixels=1000;
goptions htitle=14pt htext=10pt ftitle="albany amt/bold" ftext="albany amt";

legend1 label=none position=(bottom center) value=(&longvalues) repeat=1;

-----

Also, if you want to specifically want to control the size of the plot (such that it stays a fixed size, rather than increasing when you increase the ypixels), you can do that with a legend statement, such as...

axis1 length=5in;

proc gplot data = test;
plot height*value=sex2 / legend=legend1 cframe=cxFFFFFF vaxis=axis1;
Jennys
Calcite | Level 5
Hi Robert

Thank you so much for your efforts. Do you think that annotate might be a solution?

br
Jenny
GraphGuy
Meteorite | Level 14
I don't think that annotating the legend text manually with dev=javaimg would be possible.

The main problem I foresee is that in order for annotate to have blank space under the graph to annotate the text onto, you'd want to use a blank "footnote" to add space under the graph ... but since device=javaimg does not support gtitles (ie, titles in the graph area, like dev=png/gif does) you can't use a blank footnote to add this white-space.

footnote1 height=3in " ";

Another problem you'd be likely to run into is that dev=javaimg probably doesn't support all the annotate stuff you might want to use. I haven't tried annotate with the java/javaimg lately, but last time I tried there were enough things not supported, that I couldn't do what I wanted with it.

java/javaimg is good for making a quick/pretty *simple* graph, but when you want to do a complex graph, or have the maximum control overy your graph's appearance, I strongly recommend using the old/traditional devices such as dev=png or dev=gif, etc.
Jennys
Calcite | Level 5
Thank you. You saved me a lot of time. I will try to make it look nice either with png or just shorten the labels.

Have a nice weekend.

sas-innovate-wordmark-2025-midnight.png

Register Today!

Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.


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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 8 replies
  • 1821 views
  • 0 likes
  • 2 in conversation