- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hi, I am wanting to know if there is an easy way to group variables together on the x-axis. I have a column for the states, and and on each of their row I have gas prices. I would like my barchart graph to have 4 regions on the bottom, region 1,2,3,4. With the mean of gas prices for the states in those regions.
I am able to produce a graph that has 50 points on the x axis, is there a way I can say these states should be in region 1, and these states should be in region 2, and so on?
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
A possibility
- Create a custom format assigning multiple states to regions
- PROC SUMMARY to create the mean by region
- PROC SGPLOT VBAR on the output from PROC SUMMARY
Paige Miller
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
You don't need to summarize the data. The VBAR statement will do that for you.
data Have;
length State $2;
input State Gas;
datalines;
AL 2.89
FL 2.93
CA 3.55
NV 2.99
MN 3.05
MI 3.12
NY 3.24
MA 3.33
;
proc format;
value $Region
'AL', 'FL' /* etc */ = 'SE'
'NY', 'MA' /* etc */ = 'NE'
'MN', 'MI' /* etc */ = 'MW'
'CA', 'NV' /* etc */ = 'W';
run;
proc sgplot data=Have;
format State $Region.;
vbar State / response=Gas stat=mean;
run;
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
If I'm understanding correctly I think I have something close to what you're looking for. All you would need is to add another column containing the region you want each state to be in for the grouping.
proc sgpanel data=sashelp.cars;
panelby origin / rows=1 columns=3 novarname uniscale=row;
vbar type / response=msrp stat=mean;
run;
I used SGPANEL so that you can use your region grouping variable in the panels while keeping the TYPE variable (which would be the states in your case) on the x-axis for categorizing the bars. There are options I believe for removing the borders and such, only option I didn't see was a way to move the grouping labels (origin in the example) to the bottom. The Uniscale option makes each panel able to have unique column axes.