- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Hello
I have the bar chart below for same variable. I have plot two graphs below with a where statement "where are_you_the=1;".
Please, can you show me how to plot them side by side on the same code or same graph separated by different colors.??
proc format;
value Age
1='18-25' 2='26-35' 3='36-45' 4='46-55' 5='56-65' 6='66-75';
run;
*title "Vertical Bar Chart";
title2 "Age Distribution";
proc sgplot data=JJ noborder;
vbar Your_Age/ stat=Percent colormodel=twocolorramp;
where are_you_the=1;
xaxis label='Age' values=(1 to 6 by 1);
format Your_Age Age.;
xaxis display=(nolabel noline noticks);
yaxis display=(noline) grid;
keylegend / noborder;
*format mpg_city 8.0;
run;
title;
*title "Vertical Bar Chart";
title2 "Age Distribution";
proc sgplot data=JJ noborder;
vbar Your_Age/ stat=Percent colormodel=twocolorramp;
where are_you_the=2;
xaxis label='Age' values=(1 to 6 by 1);
format Your_Age Age.;
xaxis display=(nolabel noline noticks);
yaxis display=(noline) grid;
keylegend / noborder;
*format mpg_city 8.0;
run;
Accepted Solutions
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Not sure you want two individual side by side graphs or clustered bar graph.
If side by side use @ballardw solution. If clustered bar graph try below.
Change this
vbar Your_Age/ stat=Percent colormodel=twocolorramp;
where are_you_the=2;
To something like:
vbar Your_Age/ stat=Percent colormodel=twocolorramp group = are_you_the groupdisplay = cluster;
Specify the GROUP = variable and add the GROUPDISPLAY type to control if they're stacked or clustered. See the documentation for the details - guessed at code so check docs if there's any error, I may have the terms wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
No data provided so can't test but Proc SGPANEL is designed to create row/columns or matrix of similar graphs separated by the value of variable(s) indicated on the PANELBY statement.
I am assuming that you want two entire graphs.
From you plot perhaps:
title2 "Age Distribution"; proc sgpanel data=JJ noborder; panelby are_you_the /columns=2 vbar Your_Age/ stat=Percent colormodel=twocolorramp; format Your_Age Age.; Colaxis label='Age' values=(1 to 6 by 1) display=(nolabel noline noticks); rowaxis display=(noline) grid; keylegend / noborder; run;
Since there are multiple graphs the axis are controlled with colaxis, the axis at the bottom of the graph, and rowaxis, the one on the side. There are some options related to whether all graphs in the panel have the same or different axis displays.
This assumes you only have two values for your You_are_the variable. If you have more you may get more than one row, or if there are many values a plot that won't fit in the graph space.
NOTE: You want to be careful with multiple XAXIS or YAXIS statements in a single procedure call. One may overwrite options in the other.
If you meant that you want the 1 and 2 valued bars next to each other then you wanted a Group option:
proc sgplot data=JJ noborder; vbar Your_Age/ stat=Percent group=are_you_the groupdisplay=cluster colormodel=twocolorramp colorstat=percent; xaxis label='Age' values=(1 to 6 by 1); format Your_Age Age.; xaxis display=(nolabel noline noticks); yaxis display=(noline) grid; keylegend / noborder; *format mpg_city 8.0; run;
Group means to display values of the grouping variable, the groupdisplay=cluster means the bars are side-by-side instead of the default vertical stack. The Colorramp needs a value to apply colors with, in this case the Colorstat=percent says to use the statistic percent for the color to "ramp" the shades. If you want the colors of the Group variable to be the same for each bar of the group don't use the colorramp options, the default will assign different colors to each value of the group variable.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
Not sure you want two individual side by side graphs or clustered bar graph.
If side by side use @ballardw solution. If clustered bar graph try below.
Change this
vbar Your_Age/ stat=Percent colormodel=twocolorramp;
where are_you_the=2;
To something like:
vbar Your_Age/ stat=Percent colormodel=twocolorramp group = are_you_the groupdisplay = cluster;
Specify the GROUP = variable and add the GROUPDISPLAY type to control if they're stacked or clustered. See the documentation for the details - guessed at code so check docs if there's any error, I may have the terms wrong.
- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content
http://robslink.com/SAS/ods2/aaaindex.htm