Turn on suggestions

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

Showing results for

- Home
- /
- Programming
- /
- Graphics
- /
- Gchart Vbar : values with different colors

Options

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

🔒 This topic is **solved** and **locked**.
Need further help from the community? Please
sign in and ask a **new** question.

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

Posted 12-22-2011 06:13 AM
(10016 views)

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

1 ACCEPTED SOLUTION

Accepted Solutions

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

12 REPLIES 12

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

- Mark as New
- Bookmark
- Subscribe
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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
- Mute
- RSS Feed
- Permalink
- Report Inappropriate Content

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;

Are you ready for the spotlight? We're accepting content ideas for **SAS Innovate 2025** to be held May 6-9 in Orlando, FL. The call is **open **until September 25. Read more here about **why** you should contribute and **what is in it** for you!

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.