Data visualization with SAS programming

Highlight a certain boxplot background in a group of boxplots and make the graph narrower

Accepted Solution Solved
Reply
Contributor
Posts: 38
Accepted Solution

Highlight a certain boxplot background in a group of boxplots and make the graph narrower

Hi there,

 

I'm looking for a way to tune this PROC SGPLOT produced graph. I don't mind changing to a different procedure while the result remains the same. 

 

  1. Firstly, and more importantly, I would like to find a way to change the color of a custom background area of the plot in order to highlight a certain boxplot from a group of boxplots (see the attached figure).
  2. Secondly, I haven't found a way to control the x axis width when there is no scale on it (as in my boxplot example) because in that case the "xaxis min=0 max=6" statement doesn't make sense (I have shown also in the attached figure what I would like to achieve)

Thanks in advance for all your help and comments!!

 

sas-boxplot.PNG


Accepted Solutions
Solution
‎05-19-2017 07:44 AM
SAS Super FREQ
Posts: 1,171

Re: Highlight a certain boxplot background in a group of boxplots and make the graph narrower

[ Edited ]

It is hard to say what your x-axis range is as you have turned the axis off.  If the axis is numeric 1-6, then you could set the values=(1 to 4 by 1).  Or, you can reduce the min and max offsets.

 

For the highlighting, place a "X" reference line behind the box plot with x value ='Global', and increase the line thickness.  Use transparency and color you want.

 

proc sgplot data=sashelp.heart;
  refline 'Coronary Heart Disease' / axis=x 
          lineattrs=(thickness=70 color=yellow) transparency=0.5 ;
  vbox cholesterol / category=deathcause;
run;

 

BoxHighlight.png 

View solution in original post


All Replies
Solution
‎05-19-2017 07:44 AM
SAS Super FREQ
Posts: 1,171

Re: Highlight a certain boxplot background in a group of boxplots and make the graph narrower

[ Edited ]

It is hard to say what your x-axis range is as you have turned the axis off.  If the axis is numeric 1-6, then you could set the values=(1 to 4 by 1).  Or, you can reduce the min and max offsets.

 

For the highlighting, place a "X" reference line behind the box plot with x value ='Global', and increase the line thickness.  Use transparency and color you want.

 

proc sgplot data=sashelp.heart;
  refline 'Coronary Heart Disease' / axis=x 
          lineattrs=(thickness=70 color=yellow) transparency=0.5 ;
  vbox cholesterol / category=deathcause;
run;

 

BoxHighlight.png 

Contributor
Posts: 38

Re: Highlight a certain boxplot background in a group of boxplots and make the graph narrower

Posted in reply to Sanjay_SAS

Thanks a lot @Sanjay_SAS for your help!!

 

The offset attribute wasn't working for me because it just moves the the plot towards one side or another, but you gave me a clue on where to search for a proper solution. I finally solved it changing the THRESHOLDMIN and THRESHOLDMAX values, which control the spacing between the left and right border of the plot respectively.

 

About the line reference, it totally solved my problem in a very simple way. Thanks for such an ingenious solution!!

 

Thanks again!!

SAS Super FREQ
Posts: 1,171

Re: Highlight a certain boxplot background in a group of boxplots and make the graph narrower

[ Edited ]

You are welcome.  For future reference, it is easier to help if you attach your code and some sample data.  Then we can see what you are getting and how to help.  Version of SAS also helps.

 

The RefLine thickness will impact the offsets.  You can set the offsetmin and offsetmax to control the white space.

 

BoxHighlight.png

proc sgplot data=sashelp.heart;
  refline 'Coronary Heart Disease' / axis=x 
          lineattrs=(thickness=70 color=yellow) transparency=0.5 ;
  vbox cholesterol / category=deathcause;
  yaxis offsetmin=0.05 offsetmax=0.05;
run;

 

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 3 replies
  • 160 views
  • 1 like
  • 2 in conversation