BookmarkSubscribeRSS Feed
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 
by  percentage;

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


data plot;
set percent_dens;

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;


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!


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!



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.  Something like that might work.



Check out the Boston Area SAS Users Group (BASUG) video archives:
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. 




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.

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?



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
  • 6 replies
  • 5 in conversation