Graphics Programming

Data visualization using SAS programming, including ODS Graphics and SAS/GRAPH. Charts, plots, maps, and more!
BookmarkSubscribeRSS Feed
🔒 This topic is solved and locked. Need further help from the community? Please sign in and ask a new question.
Ullsokk
Pyrite | Level 9

I want both graphs to have the same color for the class variable. For the histogram, the coloring is set by 

styleattrs DATACOLORS=(blue red )

 But how do I set the same colors to differentiate between the classes in the vbar?

 

%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;

proc sgplot data=&_input.;
title "Distribution &response."; 
styleattrs DATACOLORS=(blue red );
histogram &response. / group=&class. transparency=0.5;
density &response.  / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;
proc sgplot data=&_input.;
styleattrs DATACOLORS=(blue red ) ;
title  "Mean &response. per &class. ";
vbar &class. / response=&response. stat=Mean name='Bar'  filltype= solid datalabel;
yaxis grid;
run;

 vbar.PNG

1 ACCEPTED SOLUTION

Accepted Solutions
PeterClemmensen
Tourmaline | Level 20

Add the GROUP= Option to the VBAR Options to make the procedure alter between the specified datacolors

 

%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;

proc sgplot data=&_input.;
title "Distribution &response."; 
styleattrs DATACOLORS=(blue red);
histogram &response. / group=&class. transparency=0.5;
density &response.  / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;

proc sgplot data=&_input.;
styleattrs datacolors=(blue red) ;
title  "Mean &response. per &class. ";
vbar &class. / group=&class. response=&response. stat=Mean name='Bar' filltype=solid datalabel;
yaxis grid;
run;

Edit: Also, you can add the transparency=0.5 to the VBAR option (as in the histogram options) to make the colors exactly the same. 

SGPlot13.png

 

 

View solution in original post

2 REPLIES 2
PeterClemmensen
Tourmaline | Level 20

Add the GROUP= Option to the VBAR Options to make the procedure alter between the specified datacolors

 

%let _input = sashelp.bweight;
%let class=black;
%let response=weight ;

proc sgplot data=&_input.;
title "Distribution &response."; 
styleattrs DATACOLORS=(blue red);
histogram &response. / group=&class. transparency=0.5;
density &response.  / group=&class. lineattrs=(pattern=solid);
xaxis display=(nolabel);
run;

proc sgplot data=&_input.;
styleattrs datacolors=(blue red) ;
title  "Mean &response. per &class. ";
vbar &class. / group=&class. response=&response. stat=Mean name='Bar' filltype=solid datalabel;
yaxis grid;
run;

Edit: Also, you can add the transparency=0.5 to the VBAR option (as in the histogram options) to make the colors exactly the same. 

SGPlot13.png

 

 

Ullsokk
Pyrite | Level 9

Thank you, didnt realise I needed to specify groups= , thought that would be implicit. 

sas-innovate-white.png

Our biggest data and AI event of the year.

Don’t miss the livestream kicking off May 7. It’s free. It’s easy. And it’s the best seat in the house.

Join us virtually with our complimentary SAS Innovate Digital Pass. Watch live or on-demand in multiple languages, with translations available to help you get the most out of every session.

 

Register now!

How to Concatenate Values

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.

SAS Training: Just a Click Away

 Ready to level-up your skills? Choose your own adventure.

Browse our catalog!

Discussion stats
  • 2 replies
  • 16718 views
  • 0 likes
  • 2 in conversation