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.

sas-innovate-2024.png

Available on demand!

Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.

 

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
  • 2 replies
  • 412 views
  • 2 likes
  • 3 in conversation