Hi,
I'm trying to draw a box plot that looks like the photo.
I have the data, but not sure what codes to use. I think the x-axis is non-linear too.
Is there anyone who can give me an example code that would match the photo as much as possible?
I assume it may go something like....
proc boxplot data=have;
plot data*group;
run;
proc sgplot data=have;
hbox data / category=group;
run;
Thank you.
Mathematically, you cannot have values < 0 on a log axis. Such values are undefined.
If you have data with values <= 0, then you will need to remove these from the data before using the data in the procedure. You can set the x-axis min value to some small value (> 0), but the shape of the graph will change based on the min value you choose, whether it is 0.1, or 0.0001. While I do not recommend this, you can replace the lowest value with "0", but that seems wrong.
You can set the x-axis to log. However, all data must be > 0.
proc sgplot data=sashelp.class;
hbox height / category=sex;
xaxis type=log min=1 logbase=2;
run;
Thank you, but is there no other way to include the 0?
Lots of the data are 0, so I'd be losing lots of data, and the distribution will look different...
It's impossible. You can't plot the log of zero because it doesn't exist. Maybe you'd like some other non-linear axis, but I don't think SAS can do that.
As Paige suggests, you could define your own transform, and transform the data yourself before using the SGPLOT procedure. You can certainly "customize" the values displayed on the x-axis back to the untransformed values using the VALUES and VALUESDISPLAY options.
Mathematically, you cannot have values < 0 on a log axis. Such values are undefined.
If you have data with values <= 0, then you will need to remove these from the data before using the data in the procedure. You can set the x-axis min value to some small value (> 0), but the shape of the graph will change based on the min value you choose, whether it is 0.1, or 0.0001. While I do not recommend this, you can replace the lowest value with "0", but that seems wrong.
Hi Paigemiller and Sanjay,
Thank you. I think what I'll do is try create a panel of histograms to compare the distributions.
Whilst Sanjay's suggestion is tempting, zero number of amino acids means 0, rather than 0.0001, so I don't think it's an option for this example.
Thank you both for your help.
I'm not sure if this is sufficient for your data but you can use a format for the x axis variable to make a log axis "lie to you" and show a 0.
data junk; do PlotGroup='Group 1','Group 2'; do loop = 1 to 5; x = rand('uniform') * 10**loop; output; end; end; run; proc format library=work; value logx 1=0 other=[best6.]; run; proc sgplot data=junk; hbox x/category= PlotGroup; xaxis type=log logbase=10 logstyle=linear ; format x logx.; run;
Are you ready for the spotlight? We're accepting content ideas for SAS Innovate 2025 to be held May 6-9 in Orlando, FL. The call is open until September 25. Read more here about why you should contribute and what is in it for you!
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.