turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- How to draw box plot with nonlinear axis

Topic Options

- RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

09-26-2017 09:47 AM - edited 09-26-2017 09:49 AM

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.

Accepted Solutions

Solution

09-26-2017
10:33 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Dani08

09-26-2017 10:26 AM

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.

All Replies

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Dani08

09-26-2017 09:58 AM

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;

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sanjay_SAS

09-26-2017 10:03 AM

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...

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Dani08

09-26-2017 10:13 AM

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.

--

Paige Miller

Paige Miller

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to PaigeMiller

09-26-2017 10:30 AM

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.

Solution

09-26-2017
10:33 AM

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Dani08

09-26-2017 10:26 AM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Sanjay_SAS

09-26-2017 10:32 AM

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.

- Mark as New
- Bookmark
- Subscribe
- RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

Posted in reply to Dani08

09-26-2017 10:45 AM

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;