Data visualization with SAS programming

Proc sgplot - multiple groups with different symbols and colours?

Reply
Contributor
Posts: 35

Proc sgplot - multiple groups with different symbols and colours?

[ Edited ]

I have multiple states that I'm trying to plot suppression and stability for using different thresholds on one plot. I've already plotted suppression and stability for different states (represented by different symbols) using a macro to generate the scatterplots for the different thresholds separately (general code is below).

 


proc sgplot data=all_states_stats;
    scatter x=Perc_unstable y=Perc_supp / group=state;
    xaxis label = 'Percent unstable';
    yaxis label = 'Percent suppressed';
    where threshold=&threshold;
run;

 

However, I want to try to put everything on the same plot where the symbol represents the state and the colour represents the threshold. I've tried removing my where statement and adding a second group= (group=threshold) statement, but that only plots everything giving all states different colours, but no way to show which point is which threshold.

 


proc sgplot data=all_states_stats;
    scatter x=Perc_unstable y=Perc_supp / group=state group=threshold;
    xaxis label = 'Percent unstable';
    yaxis label = 'Percent suppressed';
run;

 

Any help is appreciated. Thank you!

Occasional Contributor
Posts: 16

Re: Proc sgplot - multiple groups with different symbols and colours?

It sounds as if you may want to explore SGPANEL.  It wouldn't give you everything on a single plot but it would give you everything grouped together.

Respected Advisor
Posts: 2,658

Re: Proc sgplot - multiple groups with different symbols and colours?

[ Edited ]

In PROC SGPLOT, you can create attribute maps so that each state/threshold combination is assigned a specific color and symbol.

 

http://documentation.sas.com/?docsetId=grstatproc&docsetTarget=n18szqcwir8q2nn10od9hhdh2ksj.htm&docs...

 

Of course, if you have 50 states and a dozen or two dozen thresholds, a scatterplot probably would lose visual information, as no one could visually process 50 different colors and two dozen markers. There is a limit to how many color/symbol combinations can be perceived by a viewer.

--
Paige Miller
SAS Super FREQ
Posts: 1,265

Re: Proc sgplot - multiple groups with different symbols and colours?

What you need is the ability to group separately by two classifiers, one for marker symbol, one for marker color.  This is NOT supported for SCATTER plot, but IS supported in SERIES plot.  You can use SERIES plot with markers and set line thickness=0.  Then, you can use the GROUP, GROUPMC and GROUPMS to control the marker color and symbols separately.  Remember to use a Style with Attrpriority=none, or set Attrpriority=none in the ODs Graphics statement to see the different marker symbols.

Ask a Question
Discussion stats
  • 3 replies
  • 124 views
  • 0 likes
  • 4 in conversation