Data visualization with SAS programming

Different colors for bars

Accepted Solution Solved
Reply
New Contributor
Posts: 3
Accepted Solution

Different colors for bars

Hello everyone, 

 

I don't know how to change the color only for one bar (for example just for desks) and keep the same color for all the other ones? Could you please help me ? Thank you very much 

 

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/Drawing-confidence-intervals-in-gplot-usin...

 

 

data error;
  input Product $  Revenue Upper Lower;
  datalines;
Desks  2000 2200  1800
Chairs 1500 1700  1300
Lamps  1200 1100  1300
;
run;

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;

ods listing;
ods graphics / reset width=5in height=3in imagename='Error';
proc sgrender data=error template=errorbars;
run;



 

example.png

Accepted Solutions
Solution
‎10-18-2016 10:49 AM
Super User
Super User
Posts: 7,668

Re: Different colors for bars

Well, the two things jump to mind:

- Use a proc template step to define a styles for the graph, and set the colors for group 1 to be one color, then the other groups to the same color.

- Use two separate graph statements, one barchart statement for the first group setting the color, then another barchart statement for the rest of the data, setting the color there.

 

View solution in original post


All Replies
Solution
‎10-18-2016 10:49 AM
Super User
Super User
Posts: 7,668

Re: Different colors for bars

Well, the two things jump to mind:

- Use a proc template step to define a styles for the graph, and set the colors for group 1 to be one color, then the other groups to the same color.

- Use two separate graph statements, one barchart statement for the first group setting the color, then another barchart statement for the rest of the data, setting the color there.

 

New Contributor
Posts: 3

Re: Different colors for bars

Hey RW9, 

Thank you very very muuuuuuuuuuuuuuch, it worked !!!!!

Super User
Posts: 11,101

Re: Different colors for bars

Add a group variable that has one value for the "desks" and another for everything else and use the GROUP option on the scatterplot statement to use that variable to display different color (and/or marker)

New Contributor
Posts: 3

Re: Different colors for bars

Thanks ballardw ;-)

SAS Super FREQ
Posts: 925

Re: Different colors for bars

Another approach to consider is using a discrete attrmap and setting the group variable on the barchart to be the same as the category variable. In the attrmap, set the one category value to the desired color and the other values to another color. The benefit of this approach is that it will work regardless of data order.

 

Hope this helps!

Dan

☑ This topic is solved.

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

Discussion stats
  • 5 replies
  • 295 views
  • 0 likes
  • 4 in conversation