Data visualization with SAS programming

using arrows to label provinces on map (gmap)

Reply
Contributor
Posts: 57

using arrows to label provinces on map (gmap)

How can I tell sas to move labels which have little spaces on map, outside the map and instead use arrows to point to the province?

Super User
Posts: 13,084

Re: using arrows to label provinces on map (gmap)

[ Edited ]

This sounds like an annotate data set is required.

Your requirement will be to determine the x,y coordinates of where everything needs to appear on the map.

Then build a data set.

 

The SAS supplied macro %annomac should be available if you have GMAP installed. Add this code:

%annomac;

to make all of the other annotate macros available. The log will show how to get descriptions of what the various macros will help you do such as

%helpano( help);

My first step would be to use the %Maplabel macro to create a data set with the text of the labels and an approximately centered location.

If the text only needs to me moved a bit you can adjust the x and or y coordinates manually in a data step with code like

Data want_anno;

   set maplabelset;

   select (mapidvariable);

       when(someidvalue) do; x=0.5; y=0.06; end;

       when(otheridvalue) x=0.04; /* example of only one coordinate needing adjustment*/

       otherwise;

   end;

 

If you actually cannot get a location that will display the text then you need to specify:

   1) a location for the actual text label

   2) the text to display at that location   (these two can be done with a %label macro call.)

   3) specify a start location (near the text label) coordinates,

   4) end location for an arrow (the %maplabel location likely

   5) specify the arrow appearance options  (the %arrow macro should work for 3,4,5)

 

The individual annotate macros such as %arrow should appear in the online documentation as well.

 

Insert the appropriate macro calls for the id variable in the SELECT block for the ids that need the moved label and the arrow.

 

Then tell gmap to use the annotate data set. Please be aware the you can use two annotate data sets, one on the Proc Statement and one on a plot statement like CHORO.

 

If you are likely to have many of these maps it will likely be a good idea to create a permanent data set with the appropriate coordinates to reuse.

Contributor
Posts: 57

Re: using arrows to label provinces on map (gmap)

Hi ballardw, thanks for your reply and explanation. I will try that and leave a feedback. Thanks

Contributor
Posts: 57

Re: using arrows to label provinces on map (gmap)

Hi bellardw,

I wasn't successful with the code. Maybe you could use this datasets on this link to explain it better. Here is the link https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/using-colors-on-maps-gmap/m-p/457338#M1572...

 

thanks

SAS Employee
Posts: 1,031

Re: using arrows to label provinces on map (gmap)

One of my recent blog posts had a map with custom label placement, and arrows pointing from the label to the geographic area. I used lat/long coordinates for both the geographic label, and the area on the map:

 

https://blogs.sas.com/content/sastraining/2018/04/23/can-you-guess-which-10-rivers-produce-95-of-oce...

 

Here's a link to the code I used:

 

http://robslink.com/SAS/democd97/rivers_and_plastic_info.htm

 

rivers_and_plastic_map.png

Contributor
Posts: 57

Re: using arrows to label provinces on map (gmap)

Hi Robert, thanks I will try that to see if I will be successful

Contributor
Posts: 57

Re: using arrows to label provinces on map (gmap)

[ Edited ]

Hey Robert,

I have being struggling with your code samples but am not getting through.

This is my code,  maybe am doing something wrong but I can't fish it out. Please I need your help again. The labels are for the map on the link https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/using-colors-on-maps-gmap/m-p/457338#M1572...

Here is the code I have written so far

data anno_drawarrow;
length function $8 color $8;
set annolabel;
flag= 0;
xsys='2'; ysys='2'; hsys='3'; when='a';
function='label'; color='black'; size=2.5;
if id not in (ab, md, un, cd)  then 
	do;
		text=incidence; position='5'; 
		output;
	end;
else if id in (ab, md, un, cd)then 
	do;
	text=incidence; position='6'; output;
    function='move'; text=''; position=''; 
	flag=1;output;
end;

if  flag=1 then 
	do;	
        position=''; text=''; 
		function='draw'; size=.25; 
		flag=0;output;
	end;
run;

here ist the maplabel data.

I want some labels to go outside the map and use arrows to label them

Attachment
SAS Employee
Posts: 1,031

Re: using arrows to label provinces on map (gmap)

Do you have the lat/long coordinates for where you want the labels to be placed, and where you want the arrows to point to?

Contributor
Posts: 57

Re: using arrows to label provinces on map (gmap)

I'm still counting on any help

Ask a Question
Discussion stats
  • 8 replies
  • 228 views
  • 0 likes
  • 3 in conversation