Data visualization with SAS programming

gchart: changing the color of one bar

Reply
Regular Contributor
Posts: 194

gchart: changing the color of one bar

I'm using gchart to create a bar chart.
All of the bars are orange.
For bu="dog" I would like the bar to be black.
How do I accomplish this?
Thank you.
proc gchart data=goals anno=cbackanno;
hbar bu /
ascending
discrete
woutline=1
sumvar=rate
freqlabel=" " sumlabel='Total'
cframe=white
maxis=axis1
raxis=axis2
space=0.6
width=2;
run;
quit;
SAS Super FREQ
Posts: 864

Re: gchart: changing the color of one bar

You can use a small datastep and the SUBGROUP option to do it. Make sure the color value you want black ("dog" in this case) is 0. Here is an example:

[pre]
data test;
set sashelp.class;
if age=14 then color=0;
else color=1;
run;

pattern1 c=black;
pattern2 c=orange repeat=10;

proc gchart data=test;
vbar age / discrete subgroup=color;
run;
quit;
[/pre]
SAS Super FREQ
Posts: 864

Re: gchart: changing the color of one bar

A couple of adjustments to the program I posted:
1) You can remove the REPEAT=10. It is not needed.
2) You will probably want to add the NOLEGEND option to the VBAR statement.

Thanks!
Dan
Regular Contributor
Posts: 194

Re: gchart: changing the color of one bar

Looks good.
Thank you.
Post a Question
Discussion Stats
  • 3 replies
  • 112 views
  • 0 likes
  • 2 in conversation