Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
csh2157
Calcite | Level 5

Hi All, 

 

I am trying to create side by side violin plots (with 2 plots representing percentages of 2 groups) , with a boxplot overlay (the boxplot within showing mean, IQR and confidence intervals). Although I've been able to create the violin plot on its own, I am not sure how to create the boxplot. 

 

I have a dataset with a continuous variable (percentage) and binary variable (disease). My original code, for the violin plots only, is below:

 

proc sort
data = adherence 
out=sorted;
by  percentage;
run;


proc kde
data = sorted;
by disease;
univar percentage / plots=none out = percent_dens;
run;

 

data plot;
set percent_dens;
mirror=-density;
run;


proc sgpanel data=plot nocycleattrs;
panelby DisType / layout=columnlattice onepanel novarname noborder colheaderpos=bottom;
band y=value upper=density lower=mirror / fill outline;

rowaxis label="MY GRAPH" grid;

colaxis display=none;

run;

Is there any way to do this on SAS? At the very least, I would want to include more detail to my violin plot, such as mean, median, and IQR (similar to what a boxplot can tell us....but on the violin plot). Is this an alternate, more feasible solution? 

 

I would really appreciate if someone could help me out with this problem. There does not seem to a wealth of knowledge on the internet, as the use of violin plots seems to be fairly new (?). Also, I am a novice at using SAS, so any comments or tips would be helpful!!

 

 

 

Many thanks!

Christina 

6 REPLIES 6
csh2157
Calcite | Level 5

Hi Chris, 

 

Wow, thank you for the help! This definitely answers some questions I had re: including IQR and mean/median into my violin plot. 

 

On the other hand, does anyone else know anything about overlaying boxplots over violin plots? If possible, that would be the most ideal for what I'm looking for...

 

Thank again!

Christina

Quentin
Super User

Do you really want to overlay, i.e. have the box plot on top of the violin plot?  That might look messy.  Might look cleaner to have a box plot below each violin plot.  

 

Rick Wicklin has a post that uses GTL to generate a box plot below a histrogram.  https://blogs.sas.com/content/iml/2013/05/08/three-panel-visualization.html  Something like that might work.

 

ThreePanel2.png

The Boston Area SAS Users Group is hosting free webinars!
Next up: Troy Martin Hughes presents Calling Open-Source Python Functions within SAS PROC FCMP: A Google Maps API Geocoding Adventure on Wednesday April 23.
Register now at https://www.basug.org/events.
csh2157
Calcite | Level 5

Hi Quentin, 

 

Unfortunately, I would ideally like to have the overlay becauase the violin plot, on its own, is a bit too simple for describing my data. However, you bring up a good point about creating the plots separately and presenting them together! I think that this will be a good alternative if I can't figure out how to show on top of each other. 

 

Thanks!

Christina

xinlong
Calcite | Level 5

hello, can I learn about how you deal with this problem that create boxplot overlay on violin plot?  I have the same question.

ballardw
Super User

@xinlong wrote:

hello, can I learn about how you deal with this problem that create boxplot overlay on violin plot?  I have the same question.


On this forum we prefer that you start a new thread and when related to a previous one to provide a link the other thread(s) by copying the url and pasting in you question box.

That way we can tell where your responses to questions are different from the poster of the original question and readers don't get confused.

 

It is a good idea to include some example data in the form of a working data step and what you have so far. Many approaches to graphing rely on the content of a data file and we can't tell what may be needed with your data without an example. Best is also to include the code you have such as your violin plot as a starting point.

 

Also Boxplots have a LOT of options. Which features from the box plot do you need?

sas-innovate-white.png

Special offer for SAS Communities members

Save $250 on SAS Innovate and get a free advance copy of the new SAS For Dummies book! Use the code "SASforDummies" to register. Don't miss out, May 6-9, in Orlando, Florida.

 

View the full agenda.

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
  • 6 replies
  • 6437 views
  • 3 likes
  • 5 in conversation