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

BASUG is hosting free webinars ! Check out our recordings of past webinars: https://www.basug.org/videos. Be sure to subscribe to our email list for notification of future BASUG 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?

Ready to join fellow brilliant minds for the SAS Hackathon?

Build your skills. Make connections. Enjoy creative freedom. Maybe change the world. Registration is now open through August 30th. Visit the SAS Hackathon homepage.

Register today!
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.

Click image to register for webinarClick image to register for webinar

Classroom Training Available!

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

View all other training opportunities.

Discussion stats
  • 6 replies
  • 4928 views
  • 3 likes
  • 5 in conversation