BookmarkSubscribeRSS Feed
analyst_work
Obsidian | Level 7

Hi,

 

I am trying to create a scatterplot for a dataset with two groups. Number of observations in one group are much fewer compared to the other group. When I plot this graph using sgplot, most of the plot area obviously is covered by the group with higher number of observations. Is there a way to adjust this such that the plot area is split into half for each group? I assume there will be some additional white space in the area where there aren't enough observations, which is okay.

 

My basic code for creating the graph is below:

 

proc sgplot data = dataset;

scatter x= Days y= ID /group = study_arm;

run;

2 REPLIES 2
Reeza
Super User

Not automatically but you can split/break the axis based on your knowledge of the data.

proc sgplot data = dataset;

scatter x= Days y= ID /group = study_arm;
xaxis ranges=(min - someValue nextValue-high) values = (Min to Max by Interval);
run;

 

https://blogs.sas.com/content/graphicallyspeaking/2015/09/02/broken-axis-redux/

 


@analyst_work wrote:

Hi,

 

I am trying to create a scatterplot for a dataset with two groups. Number of observations in one group are much fewer compared to the other group. When I plot this graph using sgplot, most of the plot area obviously is covered by the group with higher number of observations. Is there a way to adjust this such that the plot area is split into half for each group? I assume there will be some additional white space in the area where there aren't enough observations, which is okay.

 

My basic code for creating the graph is below:

 

proc sgplot data = dataset;

scatter x= Days y= ID /group = study_arm;

run;


 

ballardw
Super User

Another option might be SGPANEL creating one graph for each value of the group variable.

 

proc sgpanel data = dataset;
   panelby study_arm  / onepanel uniscale=row columns=2 layout=columnlattice;
   scatter x= Days y= ID ;

run;

The ONEPANEL option to force all the plots into one may be overkill, the Uniscale=row means that the vertical axis will be the same and allow different horizontal axis in each panel, Columns= should be the number of levels of the group variable. If the columns is more than 3 or 4 then you may need to play with ODS Graphics settings to provide a larger plot area.

By default each panel should be the same physical size.

Catch up on SAS Innovate 2026

Dive into keynotes, announcements and breakthroughs on demand.

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

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 1991 views
  • 2 likes
  • 3 in conversation