Data visualization with SAS programming

Gchart Vbar : values with different colors

Accepted Solution Solved
Reply
Contributor
Posts: 33
Accepted Solution

Gchart Vbar : values with different colors

Hi everybody,

I am producing some Vbars with Gchart procedure, using subgroup option,it is working with no problem. Say I have 3 subgroups with 3 corresponding colors, the values for each subgroup are in black color, ana I want that for the BLUE subgroup its value be in white color , and black for the two other subgroups is this possible?

and I want the values be inside the subgroups bars, but for the Upper subgroup i Want it on the BAR.

Thanks Smiley Wink


Accepted Solutions
Solution
‎12-22-2011 08:59 AM
SAS Employee
Posts: 963

Gchart Vbar : values with different colors

Sure!

Whereas in a typical annotate data set for most procs (such as gplot and gmap), you assign Y and X variables.

For a gchart vbar, you assign a Y and Midpoint variable.

And for a subgrouped vbar, you assign a Subgroup and a Midpoint (to place the annotated text in the subgroups).

Here is an example that demonstrates annotating colored text in vbar subgroups, and controlling the color based on the subgroup value:

http://robslink.com/SAS/democd38/best_beer.htm

http://robslink.com/SAS/democd38/best_beer_info.htm

Specifically, here's how I created the annotate data set:

data anno_text; set mydata;

length function color $8;

xsys='2'; ysys='2'; when='a';

midpoint=data_order;

subgroup=medal;

function='label';

position='e';

text=trim(left(count));

if medal=1 then color='yellow';

else if medal=2 then color='black';

else if medal=3 then color='brown';

else color='pink';

run;

And here's a summary of the important parts of the gchart code:

proc gchart data=mydata;

vbar data_order / discrete

type=sum sumvar=count subgroup=medal

anno=anno_text;

run;

View solution in original post


All Replies
SAS Employee
Posts: 963

Gchart Vbar : values with different colors

For gchart vbar, you can specify colors for each subgroup, using pattern statements.

The colors will be assigned to the subgroups/bars in alphabetic order.

Here is an example:

pattern1 v=solid color=black;

pattern2 v=solid color=blue;

pattern3 v=solid color=black;

proc gchart data=sashelp.stocks;

vbar stock / type=mean sumvar=close subgroup=stock;

run;

Contributor
Posts: 33

Gchart Vbar : values with different colors

Hi Robert thank for you answer.

Maybe I wasn't so clear. My question wasn't about colors of subgroups( i have no problem with that) but I was meaning the values of each subgroup, say subgroup 1's value is 10, 2: 1 and 3: 15, what I want is that Value 10 for my first subgroup will be in WHITE color , and for the two other values Black color.

Thanks again

SAS Employee
Posts: 963

Gchart Vbar : values with different colors

I guess you'll need to provide us with an example Smiley Happy

Contributor
Posts: 33

Gchart Vbar : values with different colors

subgroup.bmp

So this was done on EXCEL, I want the same thing on SAS, so you see for BLUE Subgroup the values are in WHITE and for the last Subgroup"Cyan Blue" one the value is on the BAR. How can I do that please Smiley Happy

SAS Employee
Posts: 963

Gchart Vbar : values with different colors

Ahh - you mean the text labels in the bar subgroups!

I think the only way to have different colors for different ones is to annotate the labels, and assign the desired color in your annotate data set.

Contributor
Posts: 33

Gchart Vbar : values with different colors

Oh Okey, and can you give me a small example to do this with subgroups, I've never done it with subgroups:smileyplain:

Solution
‎12-22-2011 08:59 AM
SAS Employee
Posts: 963

Gchart Vbar : values with different colors

Sure!

Whereas in a typical annotate data set for most procs (such as gplot and gmap), you assign Y and X variables.

For a gchart vbar, you assign a Y and Midpoint variable.

And for a subgrouped vbar, you assign a Subgroup and a Midpoint (to place the annotated text in the subgroups).

Here is an example that demonstrates annotating colored text in vbar subgroups, and controlling the color based on the subgroup value:

http://robslink.com/SAS/democd38/best_beer.htm

http://robslink.com/SAS/democd38/best_beer_info.htm

Specifically, here's how I created the annotate data set:

data anno_text; set mydata;

length function color $8;

xsys='2'; ysys='2'; when='a';

midpoint=data_order;

subgroup=medal;

function='label';

position='e';

text=trim(left(count));

if medal=1 then color='yellow';

else if medal=2 then color='black';

else if medal=3 then color='brown';

else color='pink';

run;

And here's a summary of the important parts of the gchart code:

proc gchart data=mydata;

vbar data_order / discrete

type=sum sumvar=count subgroup=medal

anno=anno_text;

run;

Contributor
Posts: 33

Gchart Vbar : values with different colors

WOW I wasn't beleive that superman exists, thanks a lot

Contributor
Posts: 33

Re: Gchart Vbar : values with different colors

Hi Robert,

can I ask you an other small question. In fact I want that the text label for the upper subgroupe (Cyan blue and mybe another one, if the cyanblue subgroup have 0 observations) be ON the BAR and not inside, like in the excel example.

I have tried this but doesn't work :

data anno_text; set cross1;

length function color $8;

xsys='2'; ysys='2'; when='a';

midpoint=nat;

subgroup=grave;

function='label';

position='e';

text=trim(left(frequency));

if grave=0 then  color='white';

else if grave=1 then do; color='black' ; XC=nat; Y=frequency+1; end;

run;

SAS Employee
Posts: 963

Gchart Vbar : values with different colors

So, all the other subgroups will be in the bar segments, but the last one will be on top of the bar?  I think that could confuse users - they might assume the value on top of the bar is the total for the whole bar.

Contributor
Posts: 33

Re: Gchart Vbar : values with different colors

I totally agree with you but I am working in a company that uses this chart for graphics, and i am automating their programs.

The other problem that i have is that sometimes there are some subgroups with small values 1 or 2 so It will be better that their text labels be on the right and not inside the subgroup bar, do you see the problem?

Contributor sfo
Contributor
Posts: 66

Re: Gchart Vbar : values with different colors

[ Edited ]

Hello,

 

I am applyong the below annotation to proc gplot (in which  want to change the color of the bar not the text) but I am not getting color that I have specified. Can you please help me.

 

Thanks.

 

data anno_text;

set data;
length function color $8;
xsys='2'; ysys='2'; when='a';
midpoint=dose;
group=dose;
subgroup=VAL;
position='e';
text=" ";
if VAL="A" then color='grey';
else if VAL="B" then color='blue';
run;

 

goptions reset=all;
axis1 label=(angle=90 f=arial h=2 "Yaxis") value=(f=arial h=2) ;
axis2 label=(f=arial h=2 justify=left "Dose (mg)") value=(f=arial h=2) ;
axis3 label=none value=none;

goptions display hby=2 fby=arial;


PROC GCHART DATA=data; 
VBAR DOSE/ DISCRETE GROUP=DOSE SUBGROUP=VAL annotate=anno_text G100 NOZERO FREQ=SUBJECT TYPE=PERCENT
maxis=axis2 gaxis=axis3 raxis=axis1 inside=percent width=10 space=10 gspace=5 ;
by DRUG;
run;

Post a Question
Discussion Stats
  • 12 replies
  • 2609 views
  • 0 likes
  • 3 in conversation