Hello everyone!
I was trying to change the line size and line transparency which I have annotated on a map using proc gmap procedure. I am using SAS Enterprise Guide 7.1. However, surprisingly the line size does not change even if I keep changing the size value starting from 0.2-0.29. It only jumps to a much thicker size starting from 0.3. It is like, I can not get a thickness in between. it is either too thin or too thick.
Also, I was trying to change the transparency of these lines. How can I do that? I have tried to use the alpha RGB color codes but they did not have any effect.
I am attaching the data step that I used to create the line annotation. Thank you in advance!
data link_labels_fd;
length function color $ 8;
retain xsys ysys '2' hsys '3' when 'a' transparency 0.5;
set links4;
function='move'; output;
x = xlast; y = ylast;
if feeds = "1" then color='bib';
if feeds = "2" then color ='brown';
if feeds ="3" then color='bioy';
size = 0.3;
function='draw'; output;
run;
This is with size = 0.3
And this is with size = (0.2-0.29)
SIZE has issues with thickness as the basic code was designed for pen plotters and the number had more to do with how many times a line was traced with an offset to control width. So small changes don't make much difference. Also the appearance can be an artifact of the file type, image resolution (DPI) and your monitor resolution. The smallest image element is in effect one "dot" so if your DPI setting is 10 (not likely) a dot would be 0.1 inches and would be the thinnest line you could generate.
For the same ancient reasons, i.e. pens, the device based graph procedures like GMAP, GPLOT and GCHART do not support transparency. Proc SGMAP as a more modern does but the annotate data sets are a bit different. Look at the documentation for the %SGANNO SAS supplied macro for tools to help build annotate data sets for the SG procedures. (And %annomac for help with traditional annotate sets).
In SAS/GRAPH annotation the SIZE value rendering is dependent on the HSYS coordinate system. A different HSYS may give you access to finer line width rendering. The documentation suggests the 'thickness' is achieved by drawing multiple one pixel lines that are offset in the y-axis from the specified coordinates.
Thank you so much for your suggestion! I will try changing the HSYS.
Calling @GraphGuy
Thanks for the heads-up @Ksharp! - I hadn't noticed this one, since it wasn't in the "Graphics Programming" section.
Unfortunately, you don't get much fine-control over the line thickness in SAS/Graph GMap. I believe what you're wanting would require "sub-pixel" control of the line width. If you have very thick lines, you can somewhat control the thickness, but with thin lines (approaching 1 pixel in thickness), you don't get much control. One possible 'cheat' you might try is generating the map really big (like xpixels=8000 ypixels=6000, or something like that), and then after you're done, then use some graphics software to 'shrink' it.
Annotated lines in Gmap do support alpha-transparent colors (at least, if you're using a fairly recent version of SAS, released within the past few years). There might be some limitations depending on what output device you're using. Here's an example where I use alpha-transparent blue, with device=png:
data anno_lines;
length color $15;
xsys='3'; ysys='3'; hsys='3'; when='a';
function='move'; x=20; y=25; output;
function='draw'; x=50; y=25; size=3.0; color='A0000ff55'; output;
function='move'; x=20; y=15; output;
function='draw'; x=50; y=15; size=3.0; color='cx0000ff'; output;
run;
pattern1 v=s c=yellow;
title "Gmap with annotated transparent line";
proc gmap data=maps.us map=maps.us anno=anno_lines;
id state;
choro segment / levels=1 nolegend;
run;
Thank you so much for your reply! I did try with the transparent color of RGB. I don't why it was not working in my case. For example, when I ran the same code as yours, I am getting image like attached. What if I use bubbles. Would I able to control the transparency then? I am attaching the annotate code for the bubbles below.
data anno_depot;
set res.capacity_bubble;
length color $9;
xsys='2'; ysys='2'; hsys='3';when='a';
function='pie'; rotate=360;
/*if FIPS not in (&Biorefinery) then do;*/
size=sqrt(DepotCapacity/3.14)*.0029;
style='psolid'; color='crimson'; output;
style='pempty'; color='crimson'; output;
run;
The transparency might not be working for you if you're using an old version of SAS.
Also, it could depend on what output 'device' you are using - for example, the transparency works when I use png or gif output, but not when I use jpeg, javaimg, or actximg. I recommend using png output (If you're using EG, sometimes it's difficult to know which output EG is using).
SAS Innovate 2025 is scheduled for May 6-9 in Orlando, FL. Sign up to be first to learn about the agenda and registration!
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.
Ready to level-up your skills? Choose your own adventure.