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

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. 

 

DESIRED OUTPUT.png

 

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;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

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.

View solution in original post

7 REPLIES 7
ballardw
Super User

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.

Cruise
Ammonite | Level 13

@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;

 

Cruise
Ammonite | Level 13

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. 

gmap35.png

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;

 

ballardw
Super User

@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.

Cruise
Ammonite | Level 13

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; 
GraphGuy
Meteorite | Level 14

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;

 

korea.png

 

Cruise
Ammonite | Level 13
I still need this help. In fact, I'm gonna use this approach. Thanks a lot Robert.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 7 replies
  • 1178 views
  • 3 likes
  • 3 in conversation