Data visualization with SAS programming

Choose colors for variable values in a pie graph

Reply
Occasional Contributor
Posts: 7

Choose colors for variable values in a pie graph

Hello everyone,

 

I did a survey to know what people think about my brochure. And i would like to draw a pie with their % good or bad opinion. the variable i want to draw is " Brochure " coded in 1,2,3,4. I would like to choose the color of the pie :

1 = Very good in Green

2= Good in greenyellow

3= satisfying in red

4= not satisfying in Black

 

SAS put me random colors... is it possible to choose each color for each value of the variable drawn in the pie please ?

 

Thank you, if you find me a solution Smiley Happy

 

title1'Readibility of the brochure';
pattern1  color=green;
pattern2  color=greenyellow;
pattern3  color=red;
pattern4  color=black;

proc format;
   value brochure 1='Very Good'
               	            2='Good'
			    3='Satisfying'
			    4='Not Satisfying';
run;

proc gchart data=conso;
PIE brochure/ value=none
              percent=arrow
              slice=arrow
              noheading 
              plabel=(font='Albany AMT/bold' h=1.3 color=depk);
			  format brochure brochure.;
run;
goptions reset=all;

SAS - i don't want these colors.JPG

 

These are the colors that i would like to have.

this is what i want (Excel).JPG


this is what i want (Excel).JPG
Super User
Posts: 19,105

Re: Choose colors for variable values in a pie graph

Try the symbol statement with the colour value. 

SAS Super FREQ
Posts: 925

Re: Choose colors for variable values in a pie graph

You can do this with a GTL pie chart and a discrete attrmap. Here is a simple example:

 

proc template;
define statgraph pie;
begingraph;
discreteattrmap name="piecolors";
  value "F" / fillattrs=(color=pink);
  value "M" / fillattrs=(color=light_blue);
enddiscreteattrmap;
discreteattrvar attrvar=sex_mapped var=sex attrmap="piecolors";
layout region;
  piechart category=sex_mapped response=weight / datalabelcontent=(category percent)
           datalabelattrs=(size=20pt);
endlayout;
endgraph;
end;

proc sgrender data=sashelp.class template=pie;
run;
SAS Employee
Posts: 980

Re: Choose colors for variable values in a pie graph

I would recommend pre-summarizing your data, and specifying a few extra options in your gchart (if you want the slices to start at the 12-o'clock position, and be ordered clockwise). Here is a slightly modified version of your code, and the output:

 

data conso;
input brochure val;
datalines;
1 .30
2 .61
3 .09
4 .00
;
run;

 

title1'Readibility of the brochure';

 

pattern1 color=green;
pattern2 color=greenyellow;
pattern3 color=red;
pattern4 color=black;

 

proc format;
value brochure 1='Very Good'
2='Good'
3='Satisfying'
4='Not Satisfying';
run;

 

proc gchart data=conso;
PIE brochure/ discrete
type=sum sumvar=val
clockwise angle=90
value=none percent=arrow slice=arrow noheading
plabel=(font='Albany AMT/bold' h=1.3 color=depk);
format brochure brochure.;
run;

 

pie.png

Ask a Question
Discussion stats
  • 3 replies
  • 363 views
  • 0 likes
  • 4 in conversation