## Proc GMap: Caption and custom legend

Solved
Super Contributor
Posts: 346

# Proc GMap: Caption and custom legend

Hello,

I would like to create a world map showing various locations and a custom legend witch consecutive numbers representing the locations.

The first problem is that the caption is too "high", this is, number 3 should be on the coast, not in the Atlantic.

Second, I would like to get a legend, which shows which location is represented by which number, this is, 1 .. New York, 2.. Ann Arbor, etc.

* Sites;
Data Position;
Input @1 City \$ @30 y @42 x;
x=atan(1)/45 * x;
y=atan(1)/45 * y;
Nr=_N_;
Datalines;
New York                     40.714352   74.0059731
Ann Arbor                    42.2808256  83.7430378
Santiago de Compostela       42.8782132  8.5448445
Dalian                       38.914003   -121.614682
;
Run;

* World Map;
Data World (Rename=(long=x lat=y));
Set maps.world (Drop=x y);
Run;

* Sites+Map;
Data Combo;
Set Position World;
Run;

Proc GProject Data=Combo Out=Proj Project=Gall;
ID Cont ID;
Run; Quit;

Data Map Anno;
Set Proj;
If City='' Then Output Map;
Else Output Anno;
Run; Quit;

Data Anno;
Length Color \$8. Text \$20. Style \$25.;
Set Anno;
Retain xsys ysys '2' function 'label' when 'a';
text=Compress(Put(Nr,Best2.));
color='steel';
position='2';
size=0.8;
Output;
run;

Pattern1 v=ms r=77 c=PALG;
Title1 'Title';
Proc GMap Data=Map Map=Map;
ID Cont ID;
Choro ID / Anno=Anno COutLine=white;
Run; Quit;

Thanks&kind regards

Accepted Solutions
Solution
‎09-28-2015 05:07 AM
SAS Employee
Posts: 990

## Re: Proc GMap: Caption and custom legend

Since there is no automatic legend for the things you annotate, you'll have to create your own custom legend.

You could do that by also annotating a legend, or perhaps putting the desired legend text in a 'footnote'...

``````Title1 'Title';
footnote "1-someplace  2-other  3-another";
Proc GMap Data=Map Map=Map;
ID Cont ID;
Choro ID / nolegend Anno=Anno COutLine=white;
Run;``````

All Replies
SAS Employee
Posts: 170

## Re: Proc GMap: Caption and custom legend

For #1, use POSITION='5'; instead of '2'.  5 places the text at the center of the center.

Solution
‎09-28-2015 05:07 AM
SAS Employee
Posts: 990

## Re: Proc GMap: Caption and custom legend

Since there is no automatic legend for the things you annotate, you'll have to create your own custom legend.

You could do that by also annotating a legend, or perhaps putting the desired legend text in a 'footnote'...

``````Title1 'Title';
footnote "1-someplace  2-other  3-another";
Proc GMap Data=Map Map=Map;
ID Cont ID;
Choro ID / nolegend Anno=Anno COutLine=white;
Run;``````

Valued Guide
Posts: 765

## Re: Proc GMap: Caption and custom legend

[ Edited ]

Hi.  There is a way to add a legend that contains just the text you would like to display (map with legend attached) ...

NOTE: revised version eliminates data step that separates the projected data set into the MAP and ANNOTATE data sets and uses WHERE statements in subsequent steps to use the correct portion of the projected data set

Data Position;
Input @1 City \$20. @30 y @42 x;
x=atan(1)/45 * x;
y=atan(1)/45 * y;
Nr=_N_;
Datalines;
New York                     40.714352   74.0059731
Ann Arbor                    42.2808256  83.7430378
Santiago de Compostela       42.8782132  8.5448445
Dalian                       38.914003   -121.614682
;

* create a macro variable with text to be used in a LEGEND statement;

proc sql noprint;
select catt('j=l "',nr,': ',city,'"') into :cities separated by ' ' from position;
quit;

* combine positions and world map (no Antarctica);
Data combo;
Set position maps.world (Drop=x y Rename=(long=x lat=y) where=(cont ne 97));
run;

Proc GProject Data=Combo Out=Proj Project=Gall;
ID Cont ID;
Run;

Data Anno;
Retain xsys ysys '2' hsys '3' function 'label' style 'calibri' size 2.5 color 'steel' when 'a';
Set proj;
where ^missing(city);
text=cat(nr);
run;

goptions reset=all ftext='calibri' htext=2.5 gunit=pct;

* use the macro variable in the LEGEND statement;
legend1 origin=(3,20)pct mode=share
value=none shape=bar(.00001,.00001)pct label=(&cities);

Pattern1 v=ms r=77 c=PALG;

Title1 'MAP WITH MODIFIED LEGEND' ls=2;

Proc GMap Data=proj Map=proj;
where missing(city);
ID Cont ID;
Choro ID / Anno=Anno COutLine=white legend=legend1 statistic=first;
Run;
Quit;

🔒 This topic is solved and locked.