Hi Folks:
I'm trying to produce a map as compact as possible with minimum blank space around and legend tucked in the way it's closest can be to the body of a map as shown in the Desired Output. Legend could be placed anywhere as long as it's space efficient. My macro produce 11*3=33 pieces of maps with blank space around and legend further away as shown in Current Outout. Using proc panel jointly with my macro is not possible. But I still have to insert these maps in the table cells in Word.doc to create a 11*3 paneled view.
I attempted to copy and paste the Current Output shown in the image below in Microsoft Paint and manually produced Desired output. However, doing it 33 times would be tedious plus pixel of images reduce.
Your advise to produce Desired Output map is greatly appreciated. Please see the mock data attached to this post and the proc gmap below int he snippet.
Thanks in advance.
proc gmap data=mydata map=mapsgfk.south_korea all;
id ID;
choro LOCAL_ECONOMY / legend=legend1;
legend1 position=(middle right) across=1 mode=share
label=("&label" position=top j=c);
format LOCAL_ECONOMY comma8.4;
run;
quit;
When dealing with Gmap you need to share your GOPTIONS settings as well. Mainly because they are likely controlling the amount of space your map uses.
And LEGEND statements control where your legend goes if you want something other than the default.
Run
Proc Goptions; run;
Look in the log for either HSIZE= and VSIZE=, XMAX= YMAX= or XPIXELS= YPIXELS =. These are 3 sets of options that may control the graph size. If you want to set a size then use a Goptions statement such as:
goptions Hsize=5in Vsize=8in;
to set a horizontal size of 5 inches and vertical size of 8 inches. You can use other units of measure such as CM if preferred.
It is really best to check the documentation for the Legend statement(s) with mapping. They values you want to set will change with then number of items in your legend and the size of your graph.
Starting could be use of POSITION.
Legend1 Position= ( bottom center inside);
might get you started instead of (middle right) [Aside: what did you think the Middle right were doing? The place the legend vertically in the middle and on the right side of the graph].
If that comes close but not quite what you want then you can use OFFSET options. Adding to a legend something like Offset=(x=.5in , y=.2in) will move the whole legend to the right from the base position half an inch. Negative moves things to the left. Positive Y values move the legend up, negative down.
It is a good idea to actually provide a unit of measure like in, cm, mm or other explicit unit or PCT. Otherwise you start getting number of character display spaces.
If your bars take up too much/too little space then you get into specifying SHAPE=Bar(width, height) and likely SPACE as well.
When dealing with Gmap you need to share your GOPTIONS settings as well. Mainly because they are likely controlling the amount of space your map uses.
And LEGEND statements control where your legend goes if you want something other than the default.
Run
Proc Goptions; run;
Look in the log for either HSIZE= and VSIZE=, XMAX= YMAX= or XPIXELS= YPIXELS =. These are 3 sets of options that may control the graph size. If you want to set a size then use a Goptions statement such as:
goptions Hsize=5in Vsize=8in;
to set a horizontal size of 5 inches and vertical size of 8 inches. You can use other units of measure such as CM if preferred.
It is really best to check the documentation for the Legend statement(s) with mapping. They values you want to set will change with then number of items in your legend and the size of your graph.
Starting could be use of POSITION.
Legend1 Position= ( bottom center inside);
might get you started instead of (middle right) [Aside: what did you think the Middle right were doing? The place the legend vertically in the middle and on the right side of the graph].
If that comes close but not quite what you want then you can use OFFSET options. Adding to a legend something like Offset=(x=.5in , y=.2in) will move the whole legend to the right from the base position half an inch. Negative moves things to the left. Positive Y values move the legend up, negative down.
It is a good idea to actually provide a unit of measure like in, cm, mm or other explicit unit or PCT. Otherwise you start getting number of character display spaces.
If your bars take up too much/too little space then you get into specifying SHAPE=Bar(width, height) and likely SPACE as well.
@ballardw Thanks zillions. Do you know why offset doesn't help love the legend to the right along the x-axis little bit? So the right side of legend would line with the right end of the map? Offset is not working no matter what the number is fed there.
goptions Hsize=5in Vsize=5in;
legend1 offset=(1in ,.5in);
proc gmap data=mydata map=mapsgfk.south_korea all;
id ID;
choro LOCAL_ECONOMY / legend=legend1;
legend1 position=(bottom center inside) across=1 mode=share
label=("&label" position=top j=c);
format LOCAL_ECONOMY comma8.4;
run;
quit;
Still not succeeded 100% with below code. proc gmap is not sensitive to values I'm defining in the shape=(bar). The legend to loo large and I'd like reduce it in size.
goptions reset=pattern reset=legend;
goptions Hsize=4in Vsize=4in;
legend1 shape=bar(.15in,.15in);
proc gmap data=mydata map=mapsgfk.south_korea all;
id ID;
choro LOCAL_ECONOMY / legend=legend1;
legend1 position=(bottom center inside) across=1 mode=share
label=("label" position=top j=c);
format LOCAL_ECONOMY comma8.4;
run;
quit;
@Cruise wrote:
@ballardw Thanks zillions. Do you know why offset doesn't help love the legend to the right along the x-axis little bit? So the right side of legend would line with the right end of the map? Offset is not working no matter what the number is fed there.
goptions Hsize=5in Vsize=5in;
legend1 offset=(1in ,.5in); proc gmap data=mydata map=mapsgfk.south_korea all; id ID; choro LOCAL_ECONOMY / legend=legend1; legend1 position=(bottom center inside) across=1 mode=share label=("&label" position=top j=c); format LOCAL_ECONOMY comma8.4; run; quit;
What gdevice is the output going to, or ODS destination? If going to Java or ActiveX many of the graphic options are either not supported or only partially supported.
There may also be a fit issue if your offset value would push the legend out of the graphic area. Does the log show any messages other than the typical records used/ time stuff?
In your shown code you have two Legend1 definitions. While sometimes things will accumulate that is not always the case.
I strongly suggest moving Legend, Symbol and/or Axis definitions prior to procedures so that they are clearly defined before a procedure executes.
Thanks a lot. This worked out.
goptions Hsize=5in Vsize=5in;
legend1 position=(bottom right inside) across=1 mode=share
label=("&label" position=top j=c) offset=(-1cm,.03cm);
proc gmap data=_parameters_ map=mapsgfk.USA all;
id id;
choro &var / legend=legend1;
run; quit;
Aha - looks like you've already figured it out!
Here was the code I was working on, to help you out. (I use a cback color temporarily, to help see how much 'white space' there is...
goptions border hsize=4in vsize=4in htext=8pt device=png cback=cornsilk;
data foo; set mapsgfk.south_korea_attr;
local_economy=ranuni(123);
run;
legend1 across=1 mode=share position=(bottom right)
label=(justify=center position=top font='albany amt/bold')
shape=bar(.11in,.11in) offset=(-5pct,2pct);
title;
proc gmap data=foo map=mapsgfk.south_korea;
label local_economy='Local Economy';
format local_economy comma10.4;
id id;
choro local_economy / levels=8 range legend=legend1;
run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 16. Read more here about why you should contribute and what is in it for you!
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.
Select SAS Training centers are offering in-person courses. View upcoming courses for: