pyll
pyll

Reputation: 1764

SAS PROC GMAP Annotate Regions

I am having difficulty annotating a map I have created using the Gmap procedure (SAS 9.4).

I have a custom shape data set I have created for two regions (XX and YY). XX is actually a disjoint region made up of two shapes.

I am having two issues:

  1. The Proc is trying to draw the Area XX as one contiguous region, even though I've defined it as two separate subpolygons.
  2. The labels are not populating in the centroid of the shapes, even though I've tried using the %centroid macro to build the annotation set. The coordinates look to be correct, but the text is not showing up in the right place.

Here is the code I've put together.

data map;
    input Area $ Y X POINTORDER SUB_POLYGON_NUMBER POLYGON_NUMBER;
    cards;
XX 1 1 1 1 1
XX 2 1 2 1 1
XX 3 1 3 1 1
XX 3 2 4 1 1
XX 3 3 5 1 1
XX 2 3 6 1 1
XX 1 3 7 1 1
XX 1 2 8 1 1
XX -1 0 1 2 1
XX -2 0 2 2 1
XX -1 -2 3 2 1
YY 7 7 1 1 2
YY 7 8 2 1 2
YY 8 9 3 1 2
;
run;

data sales; 
    input Area $ Sales;
datalines;
XX 500
YY 200
;
run;

%annomac;

%CENTROID(map,anno,Area,segonly=1); 

data anno;
    set anno;
    text=Area;
    function='label';
    style="'Albany AMT/bold'";
run;

proc gmap data = sales map=map;
  id Area;
  choro Sales / nolegend annotate=anno;
run;
quit;

Upvotes: 1

Views: 690

Answers (2)

D. Josefsson
D. Josefsson

Reputation: 1052

As Joe said, this would defintely be good to have as two questions. I'll respond to the first part, since Joe has answered the second one.

By opening MAPS.Sweden, I found out that the region identifiers, your POLYGON_NUMBER and SUB_POLYGON_NUMBER, are called ID and SEGMENT. So if you change your column names according to that in the map definition, you'll get the wanted outcome.

data map;
    input Area $ Y X POINTORDER SEGMENT ID;
    cards;
XX 1 1 1 1 1
XX 2 1 2 1 1
XX 3 1 3 1 1
XX 3 2 4 1 1
XX 3 3 5 1 1
XX 2 3 6 1 1
XX 1 3 7 1 1
XX 1 2 8 1 1
XX -1 0 1 2 1
XX -2 0 2 2 1
XX -1 -2 3 2 1
YY 7 7 1 1 2
YY 7 8 2 1 2
YY 8 9 3 1 2
;
run;

I hadn't worked with gmap before, so it was quite interesting. I tried to read the documentation to find out how the columns should be named to get this to work. I did not find anything, but it should be there somewhere. Please drop a comment if you know where I can read about it.

Upvotes: 2

Joe
Joe

Reputation: 63424

I'm not sure about the first part of your question, but you probably should split them into two questions - these are two separate issues.

As far as the issue in the question title, the position of the annotate text, you have two problems.

One: your annotate text isn't using the same coordinate system. In SAS/GRAPH, this is controlled with the XSYS, YSYS, etc. variables. 4 is default, which is the value across the entire image; that's not what you want here. What you want here is 2, which is in the data space only (ie, actually on the drawn axis).

You also need to make it visible: by default it won't be drawn "over" a graph element.

data anno;
    set anno;
    text=Area;
    function='label';
    style="'Albany AMT/bold'";
    color='Red';
    when='After';
    xsys='2';
    ysys='2';
run;

I made it red to make it more visible, but you of course can use black.

Note that I tested this using the single polygon (I deleted the subpolygon=2); I'm not sure what would happen if you had both, but the centering would probably be a bit odd.

Upvotes: 1

Related Questions