BookmarkSubscribeRSS Feed
☑ This topic is solved. Need further help from the community? Please sign in and ask a new question.
GuyTreepwood
Obsidian | Level 7

Hello,


I would like to create a panel of visualizations that have vertical lines that span between min and max stat values for every category, along with a marker for mean values. I am able to get most of the way there using PROC SGPANEL using the vbox statement, however, I am not able to get rid of the boxes themselves. I would like to keep the full whiskers along with their caps, and the marker for the mean value for every categorical series.  


This is the last version of the code that I used to create the plots:

 

proc sgpanel data = dataset;
  panelby label / layout=rowlattice onepanel noheaderborder sort=data
                              novarname HEADERBACKCOLOR=white HEADERATTRS=(Size=12 Weight=Bold) proportional;
  vbox ROC /category = tuners  nofill WHISKERPCT=0 nomedian WHISKERATTRS=(color=darkgray) meanattrs=(color=darkgray size=5 symbol=x);
	rowaxis label="ROC Scores By Model"  grid labelattrs=(size=12 weight=bold) ;
	colaxis  display=(nolabel) discreteorder=data;
run;
1 ACCEPTED SOLUTION

Accepted Solutions
ballardw
Super User

Example data if you want a working solution.

You don't mention anything about outliers. Are you just wanting to connect the high and low value within each category? Plus a marker for the Mean?

 

I might summarize the data an then have a HIGHLOW plot and a SCATTER plot superimposed.

Here is a small example with SGPLOT. Your summary step would include the Panelby variable(s).

data example;
   do category= 'A', 'B', 'C';
      do i= 1 to 10;
         value = rand('integer',100);
         output;
      end;
   end;
run;

proc summary data=example nway;
   class category;
   var value;
   output out=summary min=lowval max=highval mean=meanval;
run;

proc sgplot data=summary;
   highlow x=category low=lowval high=highval/ highcap=serif lowcap=serif
                     lineattrs=(color=darkgray)
  ;
   scatter x=category y=meanval/ markerattrs=(color=darkgray size=5mm symbol=x);
run;

View solution in original post

5 REPLIES 5
ballardw
Super User

Example data if you want a working solution.

You don't mention anything about outliers. Are you just wanting to connect the high and low value within each category? Plus a marker for the Mean?

 

I might summarize the data an then have a HIGHLOW plot and a SCATTER plot superimposed.

Here is a small example with SGPLOT. Your summary step would include the Panelby variable(s).

data example;
   do category= 'A', 'B', 'C';
      do i= 1 to 10;
         value = rand('integer',100);
         output;
      end;
   end;
run;

proc summary data=example nway;
   class category;
   var value;
   output out=summary min=lowval max=highval mean=meanval;
run;

proc sgplot data=summary;
   highlow x=category low=lowval high=highval/ highcap=serif lowcap=serif
                     lineattrs=(color=darkgray)
  ;
   scatter x=category y=meanval/ markerattrs=(color=darkgray size=5mm symbol=x);
run;
GuyTreepwood
Obsidian | Level 7

This suggestion was very helpful, and I was able to create the charts that I had envisioned. However, for categories where the high and low values are either the same, or very close to each other, none of the lines show in the chart (see attachment). Is there a way to make sure the lines show (even if it looks like just one line in the chart) when the min and max values are either the same or nearly the same? 

 

proc sgpanel data=data noautolegend;
	panelby label / layout=rowlattice onepanel noheaderborder sort=data
                              novarname HEADERBACKCOLOR=white HEADERATTRS=(Size=12 Weight=Bold) proportional;
  highlow x=category low=min high=max/ highcap=serif lowcap=serif
                     lineattrs=(color=darkgray thickness=1) ;
 rowaxis label="ROC Scores By Model"  grid labelattrs=(size=12 weight=bold) ;
  	scatter x=category y=mean/ markerattrs=(color=darkblue size=4 symbol=diamondfilled); 
	colaxis  display=(nolabel) discreteorder=data;
run;
Quentin
PROC Star

It looks like the highlow plot won't draw caps for short lines.  This restriction is stated in the docs:

Restriction
Caps are not displayed for very short bars. Bar height must be at least twice the size of the cap in order for the cap to appear.

Going back to your original boxplot idea, what about adding 

boxwidth=0 lineattrs=(thickness=0)

to the options on your VBOX statement?  For a simple SGPLOT, I think that gets rid of the box.

Check out the Boston Area SAS Users Group (BASUG) video archives: https://www.basug.org/videos.
ballardw
Super User

@GuyTreepwood wrote:

This suggestion was very helpful, and I was able to create the charts that I had envisioned. However, for categories where the high and low values are either the same, or very close to each other, none of the lines show in the chart (see attachment). Is there a way to make sure the lines show (even if it looks like just one line in the chart) when the min and max values are either the same or nearly the same? 

If that represents your data then there is so little range of values I doubt a box plot makes any sense to display on that scale.

Or did you extract one panel? Perhaps you don't actually want all of the rowaxis to be the same. Try adding UNISCALE=Column to the Panelby statement.

GuyTreepwood
Obsidian | Level 7

I do not want to change the y-axis scales in the panel, so I will keep the chart as it is, without the caps, and make a note of the restriction regarding the close caps found in the documentation. 

SAS INNOVATE 2024

Innovate_SAS_Blue.png

Registration is open! SAS is returning to Vegas for an AI and analytics experience like no other! Whether you're an executive, manager, end user or SAS partner, SAS Innovate is designed for everyone on your team. Register for just $495 by 12/31/2023.

If you are interested in speaking, there is still time to submit a session idea. More details are posted on the website. 

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.

Get the $99 certification deal.jpg

 

 

Back in the Classroom!

Select SAS Training centers are offering in-person courses. View upcoming courses for:

View all other training opportunities.

Discussion stats
  • 5 replies
  • 359 views
  • 3 likes
  • 3 in conversation