I am using the GMAP procedure to map counties in a state, with the counties color coded. I am using a legend for that and it displays the way I want, no problem. I also am using a separate dataset for the annotate feature. This dataset includes points which are color coded with different colors and definitions than the variable I am using in the choro statement. How can I insert a second legend to display the meanings of the colors of the points displayed on the map? I'm aware of using subtitles, but I'd rather have a legend with the actual symbol and color showing the definition.
data anno_all; set points;
drop state;
length function $8 style $35 text $35;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='symbol'; text='V';position='5';
size=2; ;
style='marker' ;
if decert_ind = 'N' then color = 'BIGB';
else color='red' ;
run;
goptions reset=all;
pattern1 value=msolid color=BILG;
pattern2 value=msolid color=PAOY;
pattern3 value=msolid color=BIOY;
pattern4 value=msolid color=VIO;
pattern5 value=msolid color=VIYPK;
proc gmap data=state_map1 map=state_map1 anno=anno_all;
id state county;
choro risk_score / coutline=cx739436
;
run;
Here's one way to do it in a subtitle/title2 ...
title1 c=gray33 f='albany amt' h=16pt "Map with custom legend in subtitle";
title2
c=red h=12pt f='albany amt/unicode' '25cf'x
c=gray33 f='albany amt' h=10pt "=Red Ball "
c=blue h=12pt f='albany amt/unicode' '25cf'x
c=gray33 f='albany amt' h=10pt "=Blue Ball";
proc gmap data=sashelp.us_data map=mapsgfk.us;
id statecode;
choro density_1910 / levels=5;
run;
I would like to clarify about subtitles: if the subtitle can contain the symbol and color used in the map, then that would work. It doesn't have to be a separate floating legend.
You add the text to the annotate data sets with appropriate coordinates to display near the symbol.
You should investigate the macros made available by %annomac.
Add this line of code to your program before the data step where you create the annotate data set:
%annomac ;
execute it one (highlight and run).
The log will show you something like:
*** ANNOTATE macros are now available *** For further information on ANNOTATE macros, enter, %HELPANO(macroname), (for specific macros) %HELPANO(ALL), (for information on all macros) or %HELPANO (for a list of macro names)
Run the %helpano(all) to get a list of the macros and parameters (the individual macros are in the online documentation as well). This will help you create records of values appropriate to an annotate data set.
Likely you would use a %LABEL to use similar coordinates to the points you are currently using for the symbols, just change the Position parameter shift the location by a bit to avoid overwriting, or if your symbols are large enough that position won't move things enough then change the X coordinate a bit to move further.
@RandoDando wrote:
I would rather have the definitions of the colors (only 2 of them) of the points located either as a subtitle or legend on the side of the map. There are many points on the map, but only two possible categories each fit in. I've tried creating a macro with unicode and then calling the macros in a subtitle (like here:
https://blogs.sas.com/content/sasdummy/2014/06/10/sas-stars-on-thars/ ), but the symbols of the unicode are not displaying.
Annotate data sets can display values out side of the actual map area if that is your concern the Xsys and Ysys parameters indicate which address system to use.
Or Legends can be created outside of the graph area, did you actually try one? You can create pretty complex legends though you would have to include the values for your "automatic" legend currently created.
The link only references RTF text output, not graphic output.
You might want to consider using PROC SGMAP instead. That way, you can overlay a SCATTER plot instead of an annotation and be able to display multiple legends. The code would look something like the following:
proc sgmap mapresp=state_map1 mapdata=state_map1 plotdata=pointsl;
choromap risk_score / lineattrs=(color=cx739436);
scatter x=x y=y / group=decert_ind;
run;
You can even put a background map behind your chroma (or in place of it). Let me know if you have any questions.
Thanks!
Dan
What version of SAS do you have?
Here's one way to do it in a subtitle/title2 ...
title1 c=gray33 f='albany amt' h=16pt "Map with custom legend in subtitle";
title2
c=red h=12pt f='albany amt/unicode' '25cf'x
c=gray33 f='albany amt' h=10pt "=Red Ball "
c=blue h=12pt f='albany amt/unicode' '25cf'x
c=gray33 f='albany amt' h=10pt "=Blue Ball";
proc gmap data=sashelp.us_data map=mapsgfk.us;
id statecode;
choro density_1910 / levels=5;
run;
@GraphGuy Your example looks like exactly what I want, but even after copying your title code and just changing the text in side the double quotes after the equal sign, the symbols I get in my output are percent signs.
Are you using png output?
Are you using gtitles? (titles as part of the graph/png image, rather than titles outside the graph?)
Are you perhaps submitting your code through EG? (which I think might default to not-gtitles)
Thank you for your latest reply. The issue was with the environment. I simply output to a PDF, specified a style of output to change the EG default, then changed the unicode to a shaded star to match the symbols used in my annotate set as such: ('2605'x).
options orientation=landscape papersize=legal;
ods pdf style=sasweb
file="\\....\Map.pdf";
The PDF file in the output file looks nice.
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.