Data visualization with SAS programming

assigning colors to each hbar sgplots

Reply
Contributor
Posts: 57

assigning colors to each hbar sgplots

Is there anyway to assign color to each stacked bar just like using pattern in a pie chart (gchart). I want these colors to be outputted in a particular order. I will be grateful with any help

SAS Employee
Posts: 26

Re: assigning colors to each hbar sgplots

See the following post:

 

https://communities.sas.com/t5/SAS-GRAPH-and-ODS-Graphics/PROC-SGPLOT-How-to-use-Custom-Colors-in-St...

 

Let me know if this does not answer your question!

 

SAS Employee
Posts: 26

Re: assigning colors to each hbar sgplots

Posted in reply to danielduval0

Or use this example:

 

http://support.sas.com/kb/43/731.html

 

Basically, what you need is the data attrmap step which contains a datalines statement containing the variables you would like to group by color:

 

data attrmap;
/* The ID required variable contains the name of the attribute map */
/* The VALUE required variable contains the value of the GROUP variable,
which in this case is FLAVOR */
/* The FILLCOLOR variable is used to change the color for the bars created by the VBAR
statement. */

input id $ value $10. @19 fillcolor $8.;
datalines;
flavor Vanilla beige
flavor Chocolate cx663D29
flavor Strawberry pink
;
run;

 

Then, in your proc sgplot statement:

 

/* The DATTRMAP option references the attribute map data set */
proc sgplot data=icecream dattrmap=attrmap;
format sex $fmt.;
/* The ATTRID option references the name of the attribute map */
vbar sex / group=flavor response=count groupdisplay=cluster
dataskin=pressed attrid=flavor;
xaxis display=(nolabel noticks);
yaxis label='Count of Participants';
keylegend / title='Ice Cream Flavor';
run;

Contributor
Posts: 57

Re: assigning colors to each hbar sgplots

Posted in reply to danielduval0

 Thanks for the idea. I will apply it and leave a feedback

Contributor
Posts: 57

Re: assigning colors to each hbar sgplots

Thanks it worked fine.

SAS Employee
Posts: 26

Re: assigning colors to each hbar sgplots

Great news! I am glad I was able to help.

 

 

 

Ask a Question
Discussion stats
  • 5 replies
  • 213 views
  • 1 like
  • 2 in conversation