BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
HabAM
Quartz | Level 8

flumap.png

 

I am running to a couple of issue - 1) whitespace in gmap output 2) legend not maintaining proportion. The data am working with can be found https://gis.cdc.gov/grasp/fluview/main.html (Download data)

And here is my code:

 


data label;
retain flag 0 xsys ysys '2' hsys '3' when 'a' style 'swissb';
set maps.uscenter( drop=long lat);
if ocean='Y' then
do;
position='6'; output;
function='move';
flag=1;
end;
else if flag=1 then
do;
function='draw'; size=.5;
flag=0;
end;
output;
run;

 

pattern1 value=solid color=cx00C200;
pattern2 value=solid color=cx5BF700;
pattern3 value=solid color=cx8CF700;
pattern4 value=solid color=cxBAF700;
pattern5 value=solid color=cxE0F500;
pattern6 value=solid color=cxF7DF00;
pattern7 value=solid color=cxFCB100;
pattern8 value=solid color=cxFC8200;
pattern9 value=solid color=cxFA4F00;


FILENAME plots "H:\";
goptions reset=all
DEVICE=png
xpixels=412
ypixels=168
transparency
GSFNAME=plots
GSFMODE=REPLACE
NOFILEONLY;
ods _all_ close;
ods listing;
pattern1 value=solid color=cx00C200;
pattern2 value=solid color=cx5BF700;
pattern3 value=solid color=cx8CF700;
pattern4 value=solid color=cxBAF700;
pattern5 value=solid color=cxE0F500;
pattern6 value=solid color=cxF7DF00;
pattern7 value=solid color=cxFCB100;
pattern8 value=solid color=cxFC8200;
pattern9 value=solid color=cxFA4F00;


footnote1 justify=right ' Source: CDC Interactive fluview';

 

ods html;

proc gmap data=flu1 map=maps.US ;
id STATE;
choro alevel / legend=legend discrete coutline=black annotate=label name="flumap";
legend label=("ILI Activity Level" position= Top height=3pct) value=( j=right h=1.0) across=1 down=9 mode=share position=(right inside);/*Format the legend*/
run;
quit;

ods listing close;

 

I used the sashelp.zipcode to get the State two digit abbreviation.

 

Thanks

HabAM
1 ACCEPTED SOLUTION

Accepted Solutions
GraphGuy
Meteorite | Level 14

With proc gmap, the proportions of the map are always preserved (unless you use the 'stretch' option, which I would not recommend). Therefore you want the proportion of the page (controlled by xpixels & ypixels in your sample code) to somewhat resemble the proportions of the map.

 

Also, if you use a legend, by default the legend reserves space (on the top/bottom/left/right of the map, depending on what you specify in your legend statement). This usually causes a lot of white-space to be wasted. Here's a simple example, with the background colored pink, so you can 'see' the white space (or in this case pink space):

 

goptions reset=pattern reset=legend;
goptions ftext='albany amt' htext=10pt;
goptions xpixels=800 ypixels=600 cback=pink;

legend1 label=(position=top) position=(middle right) across=1
shape=bar(.15in,.15in);

title "Map with legend";
proc gmap data=sashelp.us_data map=mapsgfk.us all;
id statecode;
choro population_2010 / levels=5 legend=legend1;
run;

 

map_pink.png

 

Therefore, I usually use the 'mode=share' legend option, so the legend 'shares' the map space. And then you usually have to use x/y 'offsets' to move the legend into a place where it doesn't overlap with the map (might take some trial-and-error). Here's an example:

 

goptions reset=pattern reset=legend;
goptions ftext='albany amt' htext=10pt;
goptions xpixels=800 ypixels=600 cback=pink;

legend1 label=(position=top) position=(bottom right) across=1
shape=bar(.15in,.15in) mode=share offset=(8pct,18pct);

title "Map with legend";
title2 angle=-90 height=5 ' ';
proc gmap data=sashelp.us_data map=mapsgfk.us all;
id statecode;
choro population_2010 / levels=5 legend=legend1;
run;

 

map_legend.png

View solution in original post

6 REPLIES 6
ballardw
Super User

The data source does not tell us what choices you may have made when creating your data set so we do not have your data.

 

You should either post a picture of the data, use the PHOTOS icon at the top of the message window and browse to the location the PNG file was created (should be in the log) to show us your output.

 

Then you can tell use which white space is objectionable. Likely part of the issue may be your Xpixel and Ypixel settings. If one is too small relative to the other for the map data proportions then the other dimension is scaled to maintain the proportion which can end up with large amounts of not used graph space around the map.

Also I am not sure what you mean by "legend not maintaining proportion". You mix units in the legend definition using PCT for the legend label H and Cells for the Values (if a unit is not specified for something like H in the value then it will default to character cell).

 

You might find it helpful to move the LEGEND definition out of the procedure step as the Pattern statements are, just to keep options together.

HabAM
Quartz | Level 8

Thanks..see image attached .

HabAM
ballardw
Super User

So which white space is the issue? It isn't obvious to me what the problem might be.

 

I think picking a specific unit that matches for both your Legend label and value text , such as PCT, IN, MM or CM fixes the legend issue.

GraphGuy
Meteorite | Level 14

With proc gmap, the proportions of the map are always preserved (unless you use the 'stretch' option, which I would not recommend). Therefore you want the proportion of the page (controlled by xpixels & ypixels in your sample code) to somewhat resemble the proportions of the map.

 

Also, if you use a legend, by default the legend reserves space (on the top/bottom/left/right of the map, depending on what you specify in your legend statement). This usually causes a lot of white-space to be wasted. Here's a simple example, with the background colored pink, so you can 'see' the white space (or in this case pink space):

 

goptions reset=pattern reset=legend;
goptions ftext='albany amt' htext=10pt;
goptions xpixels=800 ypixels=600 cback=pink;

legend1 label=(position=top) position=(middle right) across=1
shape=bar(.15in,.15in);

title "Map with legend";
proc gmap data=sashelp.us_data map=mapsgfk.us all;
id statecode;
choro population_2010 / levels=5 legend=legend1;
run;

 

map_pink.png

 

Therefore, I usually use the 'mode=share' legend option, so the legend 'shares' the map space. And then you usually have to use x/y 'offsets' to move the legend into a place where it doesn't overlap with the map (might take some trial-and-error). Here's an example:

 

goptions reset=pattern reset=legend;
goptions ftext='albany amt' htext=10pt;
goptions xpixels=800 ypixels=600 cback=pink;

legend1 label=(position=top) position=(bottom right) across=1
shape=bar(.15in,.15in) mode=share offset=(8pct,18pct);

title "Map with legend";
title2 angle=-90 height=5 ' ';
proc gmap data=sashelp.us_data map=mapsgfk.us all;
id statecode;
choro population_2010 / levels=5 legend=legend1;
run;

 

map_legend.png

HabAM
Quartz | Level 8

map.PNG

 

I still have the white space in the left side, but I will play with the formatting, as suggested, until I get the desired output.

 

Thank you

HabAM
GraphGuy
Meteorite | Level 14

Reducing the xpixels will reduce the white-space on both the left & right.

Then adding an angled blank 'title2' on the right-hand side will shift some of the white space from the left to the right.

(It'll take some trial-and-error.)

 

sas-innovate-2024.png

 

Time is running out to save with the early bird rate. Register by Friday, March 1 for just $695 - $100 off the standard rate.

 

Check out the agenda and get ready for a jam-packed event featuring workshops, super demos, breakout sessions, roundtables, inspiring keynotes and incredible networking events. 

 

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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 6 replies
  • 1766 views
  • 1 like
  • 3 in conversation