turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

Find a Community

- Home
- /
- SAS Programming
- /
- SAS/GRAPH and ODS Graphics
- /
- Gchart Vbar : values with different colors

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

12-22-2011 06:13 AM

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

Accepted Solutions

Solution

12-22-2011
08:59 AM

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to kmel56

12-22-2011 08:59 AM

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;

All Replies

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to kmel56

12-22-2011 08:16 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

12-22-2011 08:22 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to kmel56

12-22-2011 08:24 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

12-22-2011 08:42 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to kmel56

12-22-2011 08:48 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

12-22-2011 08:50 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to kmel56

12-22-2011 08:59 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

12-22-2011 09:05 AM

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

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to kmel56

12-23-2011 05:00 AM

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;

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to kmel56

12-23-2011 08:08 AM

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.

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

12-23-2011 08:10 AM

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?

- Mark as New
- Bookmark
- Subscribe
- Subscribe to RSS Feed
- Highlight
- Email to a Friend
- Report Inappropriate Content

Posted in reply to RobertAllison_SAS

01-24-2016 01:38 AM - edited 01-24-2016 02:12 AM

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;