Dear all,
I created a graph using sgpanel but since my legend is too large, it compresses the graph which doesn't make it look nice. On searching through the internet I came accross this article which says Microsoft Word - More to it than Meets the Eye.doc (lexjansen.com)
a Legend can be created seperate from the graph using an annotate facility. I have being tring to follow up the description but am not really getting it.
Could someone maybe help?
I used sashelp.cars here as test data. Here is my code:
I tried to transform sashelp.cars data to look like my data:
data have;
length make_combi $50;
set sashelp.cars;
if _n_ <= 20 then do; make_combi="Accura"; end;
if _n_ >= 21 and _n_<=40 then do; make_combi= "Dodge+Buick+Ford" ; end;
if _n_ >= 41 and _n_<=60 then do; make_combi= "Dodge+Buick+GMC"; end;
if _n_ >= 61 and _n_<=75 then do; make_combi="Accura+Audi+BMW"; end;
if _n_ >= 76 and _n_<=90 then do; make_combi="Accura+Buick"; end;
if _n_ >= 91 and _n_<=100 then do; make_combi= "Chevrolet"; end;
if _n_ >= 101 and _n_<=120 then do; make_combi= "Honda"; end;
if _n_ >= 121 and _n_<=160 then do; make_combi="Accura+Buick+BMW"; end;
if _n_ >= 161 and _n_<=170 then do; make_combi= "Hummer"; end;
if _n_ >=171 and _n_<=180 then do; make_combi= "Hummer+Buick" ; end;
if _n_ >= 181 and _n_<=190 then do; make_combi= "Hummer+Buick+BMW"; end;
if _n_ >= 191 and _n_<=200 then do; make_combi= "Hummer+Buick+Hyundai"; end;
if _n_ >= 201 and _n_<=210 then do; make_combi="Accura+Buick+Chevrolet"; end;
if _n_ >= 211 and _n_<=220 then do; make_combi="Cadillac"; end;
if _n_ >= 221 and _n_<=230 then do; make_combi="Chrysler"; end;
if _n_ >= 231 and _n_<=240 then do; make_combi="Chrysler+Audi"; end;
if _n_ >= 281 and _n_<=290 then do; make_combi= "Chrysler+Buick" ; end;
if _n_ >= 291 and _n_<=300 then do; make_combi= "Jaguar"; end;
if _n_ >= 301 and _n_<=310 then do; make_combi="Chrysler+Buick+BMW"; end;
if _n_ >= 311 and _n_<=320 then do; make_combi= "Jaguar+BMW"; end;
if _n_ >= 321 and _n_<=330 then do; make_combi="BMW"; end;
if _n_ >= 231 and _n_<=340 then do; make_combi= "Jaguar+Hyundai"; end;
if _n_ >= 341 and _n_<=360 then do; make_combi="Dodge" ; end;
if _n_ >= 361 and _n_<=380 then do; make_combi= "Dodge+Buick+BMW" ; end;
if _n_ >= 381 and _n_<=390 then do; make_combi="Dodge+Chevrolet" ; end;
if _n_ >= 391 and _n_<=400 then do; make_combi= "Jaguar+Audi"; end;
if _n_ >=401 and _n_<=420 then do; make_combi= "Dodge+Audi"; end;
if _n_ >= 421 and _n_<=440 then do; make_combi= "Dodge+Buick" ; end;
keep make type make_combi;
run;
I then created the format using proc format as described in the paper
proc format;
value BarLabel 1="Accura"
2= "Accura+Audi+BMW"
3= "Accura+Buick"
4= "Accura+Buick+BMW"
5= "Accura+Buick+Chevrolet"
6= "Cadillac"
7= "Chrysler"
8= "Chrysler+Audi"
9= "Chrysler+Buick"
10= "Chrysler+Buick+BMW"
11= "BMW"
12= "Dodge"
13= "Dodge+Chevrolet"
14= "Dodge+Audi"
15= "Dodge+Buick"
16= "Dodge+Buick+BMW"
17= "Dodge+Buick+Ford"
18= "Dodge+Buick+GMC"
19= "Chevrolet"
20= "Honda"
21= "Hummer"
22= "Hummer+Buick"
23= "Hummer+Buick+BMW"
24= "Hummer+Buick+Hyundai"
25= "Ford"
26= "Infiniti"
27= "Hyundai"
28= "Audi"
29= "Audi+Hyundai"
30= "Jaguar"
31= "Jaguar+BMW"
32= "Jaguar+Hyundai"
33= "Jaguar+Audi"
34= "Jaguar+Audi+Hyundai"
35= "Jaguar+Buick"
36= "Jaguar+Buick+BMW"
37= "Jaguar+Buick+Chevrolet"
38= "MINI"
39= "Buick"
40= "Buick+BMW"
41= "Buick+Chevrolet"
42= "Buick+Ford"
43= "Buick+Hyundai"
44= "Buick+GMC"
45= "GMC"
;
value BarColor 1= "CX00FA9A"
2= "CX0000FF"
3= "CXFFE4C4"
4= "CX696969"
5= "CX8B0000"
6= "CX5F9EA0"
7= "CXB8860B"
8= "CX8FBC8F"
9= "CX1E90FF"
10= "CXADFF2F"
11= "CXFFEBCD"
12= "CXF08080"
13= "CX00CED1"
14= "CXFFDAB9"
15= "CXB22222"
16= "CX00FFFF"
17= "CXFF8C00"
18= "CXE0FFFF"
19= "CX4682B4"
20= "CXE0FFFF"
21= "CX40E0D0"
22= "CX008080"
23= "CX8B4513"
24= "CX4169E1"
25= "CXBC8F8F"
26= "CX696969"
27= "CXD2691E"
28= "CX7FFF00"
29= "CXBDB76B"
30= "CXE9967A"
31= "CX483D8B"
32= "CXDCDCDC"
33= "CX2F2F2F"
34= "CXFFF0F5"
35= "CXFF0000"
36= "CX808000"
37= "CXFFDEAD"
38= "CX7B68EE"
39= "CX0000CD"
40= "CX20B2AA"
41= "CXADFF2F"
42= "CXFFD700"
43= "CXFF1493"
44= "CX8B008B"
45= "CX8FBC8F"
;
run;
Here is the code for the annotate data, the %cbar is not working (so the colors are also not showing) that is why I commented it out, Or maybe am doing something wrong. Or there is a better way to do that
data want;
set have;
do i=1 to max(_n_);
BarLabel= put(i, BarLabel.);
BarColor= put(i, BarColor.);
%annomac;
%bar(4,44-(i*3),8,42-(i*3),black, 0, e);
*%cbar(4,44-(i*3), 8,42-(i*3), BarColor,3,s);
%label(10,43.3-(i*3), BarLabel, black, 0,0,0.5,'Arial',6);
end;
run;
to create the legend using
filename legend "mypath\test2.gif";
goptions device=gif gsfname=legend hsize=5in vsize=12in;
proc gslide anno=want;
run;
quit;
Thanks for any help
... View more