Data visualization with SAS programming

Change color of bars

Accepted Solution Solved
Reply
Frequent Contributor
Posts: 93
Accepted Solution

Change color of bars

Hi all,

This is the very first time I am using SAS to do a customized chart. I have SAS 9.3

I tried to draw confidence intervals in gplot and find the thread

So I bascially followed Sanjay's codes like.

proc template;   define statgraph errorbars;     begingraph;       entrytitle 'Product Revenue';       layout overlay / yaxisopts=(offsetmin=0) xaxisopts=(display=(ticks tickvalues line));      barchart x=product y=revenue;         scatterplot x=product y=revenue / yerrorupper=upper yerrorlower=lower markerattrs=(size=0);       endlayout;     endgraph;   end; run; 

But, I cannot figure out how to change the color of the bars. Can anyone tell me how to do that?

Here is my data:

daysMeanUpperLower
0 day34.3631.9736.76
1-3 days37.7533.8741.64
4-7 days42.6938.4346.96
>7 days48.6043.0754.12

"days" is my x-axis, and "Mean" is the variable I want to plot for a bar chart, with 95% CI of upper and lower values.

Thanks so much!

Lizi


Accepted Solutions
Solution
‎02-05-2015 10:53 AM
SAS Super FREQ
Posts: 1,080

Re: Change color of bars

If you have SAS 9.3 or later, you can do this using the SGPLOT procedure.

Use LIMITATTRS to change the color of the error bars.

You can change the color of the bars themselves using FILLATTRS.  SGPLOT has very extensive features and you can see product documentation for all the details.

title 'Revenue by Product';

proc sgplot data=error;

  vbarparm category=product response=revenue / limitupper=upper limitlower=lower

           limitattrs=(color=red);

  xaxis display=(nolabel);

run;

Bar_Error_SG.png

View solution in original post


All Replies
SAS Super FREQ
Posts: 1,080

Re: Change color of bars

It is always useful to include the Version number of SAS you are using, as the answer depends on that information.  Preferably, include a full working program with sample data you have already built. SGPLOT may be sufficient for you needs.  Please see 

Frequent Contributor
Posts: 93

Re: Change color of bars

Sorry, I'll keep that in my mind. I have SAS 9.3. I also just added some sample data in my question. Thanks a lot.

Solution
‎02-05-2015 10:53 AM
SAS Super FREQ
Posts: 1,080

Re: Change color of bars

If you have SAS 9.3 or later, you can do this using the SGPLOT procedure.

Use LIMITATTRS to change the color of the error bars.

You can change the color of the bars themselves using FILLATTRS.  SGPLOT has very extensive features and you can see product documentation for all the details.

title 'Revenue by Product';

proc sgplot data=error;

  vbarparm category=product response=revenue / limitupper=upper limitlower=lower

           limitattrs=(color=red);

  xaxis display=(nolabel);

run;

Bar_Error_SG.png

SAS Super FREQ
Posts: 1,080

Re: Change color of bars

Note: VBARPARM draws the data as you provide it without any summarization.  It is designed for pre summarized data by category, and allows you to specify your own error limits.  If you have two observations for "Desks", a second bar will be drawn over the first one for "Desks".   You will see a log message.


If you want the statement to summarize data, use VBAR, but you will then get the error bars based on the other statement options.

Frequent Contributor
Posts: 93

Re: Change color of bars

Thanks, Sanjay.

I have one more question: is it possible to change the font of x-axis(Desks, Chairs, Lamps) /y-axis (0, ...,2000) labels?

SAS Super FREQ
Posts: 1,080

Re: Change color of bars

Most things can be customized.  See VALUEATTRS or LABELATTRS on the axis statements.

This Blog has many examples of SGPLOT usage:

http://blogs.sas.com/content/graphicallyspeaking/

Super Contributor
Posts: 252

Re: Change color of bars

Lizi,

I agree with Sanjay regarding the useful information to include. i.e. the version number of SAS, and please see the tip.

I'm guessing that you need to include the following within your SCATTERPLOT statement to change the color of the bars.

  ERRORBARATTRS = (color = red)

You can also choose other colors apart from red.

Thanks.

Frequent Contributor
Posts: 93

Re: Change color of bars

Thanks, Dirisks! I tried including ERRORBARATTRS = (color = red) at the end of the SCATTERPLOT statement. It looks there is no error message, but I do not see the bar color change.

☑ This topic is SOLVED.

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

Discussion stats
  • 8 replies
  • 1998 views
  • 8 likes
  • 3 in conversation