BookmarkSubscribeRSS Feed
Vic3
Obsidian | Level 7

I'm putting several groups of points on the same plot:

             

proc sgplot data=mydata;
styleattrs datasymbols=(circlefilled) datacontrastcolors=(red blue); scatter x=xvar y=yvar / group=rate markerattrs=(size=5); run;

One of the group (point cloud) is larger and more dense than the other. It is by default displayed on the foreground and obscures the smaller one.  I would like to bring the smaller point cloud to the front and larger to the back. Is there a way to manipulate in what sequence the groups are displayed?

I tried sorting the data in ascending or descending order, but it has no affect on how the points are plotted.

3 REPLIES 3
ballardw
Super User

There are several ways to deal with such overlay issues.

One is to sort the data so that the group values are seen in a different order. Most of these procedures assign the first color/marker/line in the current active ODS STYLE to the first seen.

 

Another is to change the ODS style used which would be done as an option on and ODS destination statement such as RTF

ods rtf file="<path>\file.rtf" style=Htmlblue;

The results window uses the ODS HTML output.

 

To provide much more positive control related to colors, sizes, marker symbols, text color, line colors and patterns you can use a DATTRMAP data set to specific properties for specific values of the Group variable.

 

Another approach is to add a TRANSPARENCY to the Scatter plot options. A value larger than 0 (but <=1) is a level of transparency. The default is 0 or opaque which obscures completely. If you try TRANSPARENCY= 0.5 you might see some discernible over lay values. If you have lots of points even more transparent may help.

 

Smaller makers or different symbol, such as  Circle (unfilled means the lines may intersect but may avoid big blots of color), or Asterisk or Plus signs, which take up less visual space.

 

If you provide some example data in the form of a working data step we may be able to suggest exact code that works with your values.

 

Instructions here: https://communities.sas.com/t5/SAS-Communities-Library/How-to-create-a-data-step-version-of-your-dat... will show how to turn an existing SAS data set into data step code that can be pasted into a forum code box using the </> icon or attached as text to show exactly what you have and that we can test code against.

BrunoMueller
SAS Super FREQ

I suggest to use an attribute map, this allows you control the appearance of the markers.

See below for an example:

ods graphics / reset=all;
data attrmap;
  infile cards dsd dlm="," truncover;
  input id $ value $ MARKERTRANSPARENCY MARKERCOLOR $ markersymbol : $32. ;
cards4;
type, Hybrid, 0.8 , pink   , CircleFilled
type, Sedan , 0.8 , green  , CircleFilled
type, Sports, 0.8 , blue   , CircleFilled
type, SUV   , 0.7 , yellow , CircleFilled
type, Truck , 0   , red    , StarFilled
type, Wagon , 0.5 , black  , StarFilled
;;;;

proc sgplot data=sashelp.cars dattrmap=attrmap;
  scatter x=invoice y=horsepower / group=type attrid=type;
run;

Also have a look at the GROUPORDER= option

 

BrunoMueller
SAS Super FREQ

Another approach would be to split up the Y value into different variables and use several SCATTER statement. The last SCATTER statement will be the one that is on top of any other.

data mycars;
  set sashelp.cars;
  if type = "Truck" then do;
    hp_fore = horsepower;
  end;
  else do;
    hp_back = horsepower;
  end;
run;

proc sgplot data=mycars;
  scatter x=invoice y=hp_back / markerattrs=(symbol=plus ) transparency=0.5 ;
  scatter x=invoice y=hp_fore / ;
run;

SAS Innovate 2025: Register Now

Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 3 replies
  • 601 views
  • 0 likes
  • 3 in conversation