Hello,
I need help with creating 1) horizontal stacked bar chart and then 2) giving certain RGB color to a scale:
here is the dataset I have:
treatment_group | scale | percent |
drug | 0 | . |
drug | 1 | 2.5 |
drug | 2 | 2.5 |
drug | 3 | 12.5 |
drug | 4 | 24.2 |
drug | 5 | 23.3 |
drug | 6 | 9.2 |
drug | 7 | 25.8 |
control | 0 | . |
control | 1 | 0.4 |
control | 2 | 6.0 |
control | 3 | 12.0 |
control | 4 | 25.7 |
control | 5 | 24.1 |
control | 6 | 12.4 |
control | 7 | 19.3 |
I would like to create a stacked bar graph HORIZONTAL. Right now, I have it vertical.
proc sgplot data=a.FreqOut;
vbar treatment_group/ response=Percent group=scale groupdisplay=stack;
xaxis discreteorder=data;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total";
run;
Also for Each scale, I would like to give a RGB color
For examples
- Scale 7 should have certain color:cx9999ff
- Scale 6 should have certain color=cx993366
- Scale 5 should have certain color=cxffffcc
I tried but no luck!
pattern1 v=solid color=cx9999ff;
pattern2 v=solid color=cx993366;
pattern3 v=solid color=cxffffcc;
Any help would be appreciated!!
Hello,
I need help with creating 1) horizontal stacked bar chart and then 2) giving certain RGB color to a scale:
here is the dataset I have:
treatment_group | scale | percent |
drug | 0 | . |
drug | 1 | 2.5 |
drug | 2 | 2.5 |
drug | 3 | 12.5 |
drug | 4 | 24.2 |
drug | 5 | 23.3 |
drug | 6 | 9.2 |
drug | 7 | 25.8 |
control | 0 | . |
control | 1 | 0.4 |
control | 2 | 6.0 |
control | 3 | 12.0 |
control | 4 | 25.7 |
control | 5 | 24.1 |
control | 6 | 12.4 |
control | 7 | 19.3 |
I would like to create a stacked bar graph HORIZONTAL. Right now, I have it vertical.
proc sgplot data=a.FreqOut;
vbar treatment_group/ response=Percent group=scale groupdisplay=stack;
xaxis discreteorder=data;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total";
run;
Also for Each scale, I would like to give a RGB color
For examples
- Scale 7 should have certain color:cx9999ff
- Scale 6 should have certain color=cx993366
- Scale 5 should have certain color=cxffffcc
I tried but no luck!
pattern1 v=solid color=cx9999ff;
pattern2 v=solid color=cx993366;
pattern3 v=solid color=cxffffcc;
Any help would be appreciated!!
You posted this in SAS VA, are you using SAS Visual Analytics, which is a GUI interface or programming in Base?
Assuming you're using Base - Pattern statements apply to SAS/GRAPH not SGPLOT. You can use the STYLEATTRS() to control the colour. You may want a data attribute map, but try adding the following statement after your SGPLOT statement, but before your VBAR statement.
styleattrs datacolors=(cx9999ff cs993366 cxffffcc);
@radhikaa4 wrote:
Hello,
I need help with creating 1) horizontal stacked bar chart and then 2) giving certain RGB color to a scale:
here is the dataset I have:
treatment_group
scale
percent
drug
0
.
drug
1
2.5
drug
2
2.5
drug
3
12.5
drug
4
24.2
drug
5
23.3
drug
6
9.2
drug
7
25.8
control
0
.
control
1
0.4
control
2
6.0
control
3
12.0
control
4
25.7
control
5
24.1
control
6
12.4
control
7
19.3
I would like to create a stacked bar graph HORIZONTAL. Right now, I have it vertical.
proc sgplot data=a.FreqOut;
vbar treatment_group/ response=Percent group=scale groupdisplay=stack;
xaxis discreteorder=data;
yaxis grid values=(0 to 100 by 10) label="Percentage of Total";
run;
Also for Each scale, I would like to give a RGB color
For examples
- Scale 7 should have certain color:cx9999ff
- Scale 6 should have certain color=cx993366- Scale 5 should have certain color=cxffffcc
I tried but no luck!
pattern1 v=solid color=cx9999ff;
pattern2 v=solid color=cx993366;
pattern3 v=solid color=cxffffcc;
Any help would be appreciated!!
Join us for SAS Innovate 2025, our biggest and most exciting global event of the year, in Orlando, FL, from May 6-9. Sign up by March 14 for just $795.
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.
Ready to level-up your skills? Choose your own adventure.