BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Dani08
Obsidian | Level 7

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

1 ACCEPTED SOLUTION

Accepted Solutions
Jay54
Meteorite | Level 14

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.

View solution in original post

7 REPLIES 7
Jay54
Meteorite | Level 14

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;

Dani08
Obsidian | Level 7

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

PaigeMiller
Diamond | Level 26

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
Jay54
Meteorite | Level 14

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.

Jay54
Meteorite | Level 14

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.

Dani08
Obsidian | Level 7

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.

 

ballardw
Super User

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;

sas-innovate-2024.png

Don't miss out on SAS Innovate - Register now for the FREE Livestream!

Can't make it to Vegas? No problem! Watch our general sessions LIVE or on-demand starting April 17th. Hear from SAS execs, best-selling author Adam Grant, Hot Ones host Sean Evans, top tech journalist Kara Swisher, AI expert Cassie Kozyrkov, and the mind-blowing dance crew iLuminate! Plus, get access to over 20 breakout sessions.

 

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.

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
  • 7 replies
  • 1237 views
  • 0 likes
  • 4 in conversation