Data visualization with SAS programming

Non-unified axis (different offsets) for 2 layouts with discrete axis (barcharts) GTL

Accepted Solution Solved
Reply
Occasional Contributor
Posts: 6
Accepted Solution

Non-unified axis (different offsets) for 2 layouts with discrete axis (barcharts) GTL

Hi SAS Community!

 

I'm trying to produce waterfall plots with extremely different sample sizes for 2 treatment groups. The problem is that width of the bars differs a lot in the case with very different sample sizes. I'm trying to place bars in the center for the group with small sample size using big offsets and minimize the barwidth but I faced the problem that SAS aligns boundary ticks one under other:

 

win7-amd64-sas94-vbox [Работает] - Oracle VM VirtualBox 2016-01-19 16.27.10.png

I need to minimize offsets for the bottom layout while save offsets for the top layout. As on the image below:

 

win7-amd64-sas94-vbox [Работает] - Oracle VM VirtualBox 2016-01-19 16.34.51.png


But sas ignores offsets options and takes a maximum of the offsets from top and bottom layout.

 

Below please see sas code used to produce outputs:

 

data sample;
	do x = 1 to 5;
		y = ranuni(0)*100;
		output;
	end;
	do x2 = 1 to 20;
		y2 = ranuni(0)*100;
		output;
	end;
run;

proc template;
	define statgraph Statgraph.test;
	begingraph;
		layout lattice / rows=2 columns=1;

			layout overlay / xaxisopts=(offsetmin=.35 offsetmax=.35);
				barchart x=x y=y;
			endlayout;

			layout overlay / xaxisopts=(offsetmin=.05 offsetmax=.05);
				barchart x=x2 y=y2;
			endlayout;

		endlayout;
	endgraph;
	end;
run;

ods html;

proc sgrender data=sample template=Statgraph.test;
run;

 

 

 

Options for layout lattice as rowdatarange do not affect on graphs. Seems that the problem is related to discrete axis type which is the only type allowed for barchart. Could anyone help with this problem? Thanks.

 

Kind regards!

 

 

 

 


Accepted Solutions
Solution
‎01-19-2016 10:13 AM
SAS Super FREQ
Posts: 1,138

Re: Non-unified axis (different offsets) for 2 layouts with discrete axis (barcharts) GTL

Break the "sibling" relationship by adding a LAYOUT GRIDDED around the second LAYOUT OVERLAY.

 

proc template;
  define statgraph Statgraph.test;
  begingraph;
    layout lattice / rows=2 columns=1;

      layout overlay / xaxisopts=(offsetmin=.35 offsetmax=.35);
        barchart x=x y=y;
      endlayout;

      layout gridded;
        layout overlay / xaxisopts=(offsetmin=.05 offsetmax=.05);
          barchart x=x2 y=y2;
        endlayout;
      endlayout;

    endlayout;
endgraph;
end;
run;

 

WaterfallPanel.png

View solution in original post


All Replies
SAS Super FREQ
Posts: 3,620

Re: Non-unified axis (different offsets) for 2 layouts with discrete axis (barcharts) GTL

I'm not sure how you intend to use this display, but consider whether you can add a group variable and then call the SGPANEL procedure to plot both groups in a column. The SGPANEL procedure supports many options for equating or not equating axes.

 

data sample;
   group = 1;
	do x = 1 to 5;
		y = ranuni(123)*100;
		output;
	end;
   group = 2;
	do x = 1 to 20;
		y = ranuni(123)*100;
		output;
	end;
run;

proc sgpanel data=sample;
   panelby group / columns=1;
   vbar x / response=y;
run;

SGPanel2.png

 

Occasional Contributor
Posts: 6

Re: Non-unified axis (different offsets) for 2 layouts with discrete axis (barcharts) GTL

Hi Rick,

 

Thank you for the quick reply, your solution works but I need something which will work with my approach, I have very "big" macro and it will consume a huge amount of time to rewrite using your approach

Solution
‎01-19-2016 10:13 AM
SAS Super FREQ
Posts: 1,138

Re: Non-unified axis (different offsets) for 2 layouts with discrete axis (barcharts) GTL

Break the "sibling" relationship by adding a LAYOUT GRIDDED around the second LAYOUT OVERLAY.

 

proc template;
  define statgraph Statgraph.test;
  begingraph;
    layout lattice / rows=2 columns=1;

      layout overlay / xaxisopts=(offsetmin=.35 offsetmax=.35);
        barchart x=x y=y;
      endlayout;

      layout gridded;
        layout overlay / xaxisopts=(offsetmin=.05 offsetmax=.05);
          barchart x=x2 y=y2;
        endlayout;
      endlayout;

    endlayout;
endgraph;
end;
run;

 

WaterfallPanel.png

SAS Super FREQ
Posts: 3,620

Re: Non-unified axis (different offsets) for 2 layouts with discrete axis (barcharts) GTL

Since you mention waterfall plots, you might want to look at the article "Create a waterfall chart in SAS."

Sanjay has also written about this kind of chart in "Clinical Graphs."

☑ This topic is solved.

Need further help from the community? Please ask a new question.

Discussion stats
  • 4 replies
  • 379 views
  • 3 likes
  • 3 in conversation