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
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;
For #1, use POSITION='5'; instead of '2'. 5 places the text at the center of the center.
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;
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;
Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.
If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website.
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.