Solved
Contributor
Posts: 40

Stacked barplot

Hello to all!

Today on this nice and sunny Sunday I am fighting with one problem :smileyangry:

I have data that look like this

id     a     b     c

1 0.405 0.316 0.279

2 0.622 0.323 0.055

3 0.286 0.518 0.196

4 0.637 0.309 0.054

5 0.091 0.879 0.030

...

as you can notice a+b+c sum to 1 (100%).

I would like to make barplot with max on y axis equals 1 (100%), id on x axis. But o would like that bar is divided in three parts where color would indicate is it value a, b, or c

Imagine this as a plot

100%| c     c     c     c     c

| c     b     c     b     b

| c     b     b     b     b

| b     b     b     b     b

| b     a     b     a     b

| b     a     b     a     b

| a     a     b     a     b

| a     a     a     a     b

| a     a     a     a     b

| a     a     a     a     a

---------------------------------------------------------

1     2     3     4     5                       id

or look this one

Thank you a lot!!!

Accepted Solutions
Solution
‎07-07-2014 03:54 AM
Contributor
Posts: 40

Re: Stacked barplot

Hello again,

first of all sorry for taking your time guys. I haven't search long enough here on Community forum for a solution before I asked a question.

So after no one replied I was forced to put more effort.

Using previous topic    I followed advises from RobertAllison@SAS and Sanjay@SAS and made this:

data structure (keep = id a b c);

infile "C:\..." ;

input id 1-3 id2 \$ 9-13 ms \$ 17-19 pop \$ 24-27 a b c;

run;

proc transpose data = structure out = sss (rename = (_name_=measure col1=value));

by id;

run;

goptions reset = all;

ods graphics on/

imagefmt = png

width =32cm

height = 10cm

imagemap = on

border=off

imagename = "structurebarplot";

proc sgplot data = sss noautolegend;

label measure="Measure";

vbar id/response= value group=measure

BARWIDTH=1  NOOUTLINE;

yaxis values = (0 to 1 by 0.1);

run;

this created this graph:

I have to play with xaxis a bit more but this is already good.

This is actually plot produced from Structure software. Structure by itself creates this kinf of plots but they are in low resolution. This was created from Structure output.

Hope this will help someone

All Replies
Solution
‎07-07-2014 03:54 AM
Contributor
Posts: 40

Re: Stacked barplot

Hello again,

first of all sorry for taking your time guys. I haven't search long enough here on Community forum for a solution before I asked a question.

So after no one replied I was forced to put more effort.

Using previous topic    I followed advises from RobertAllison@SAS and Sanjay@SAS and made this:

data structure (keep = id a b c);

infile "C:\..." ;

input id 1-3 id2 \$ 9-13 ms \$ 17-19 pop \$ 24-27 a b c;

run;

proc transpose data = structure out = sss (rename = (_name_=measure col1=value));

by id;

run;

goptions reset = all;

ods graphics on/

imagefmt = png

width =32cm

height = 10cm

imagemap = on

border=off

imagename = "structurebarplot";

proc sgplot data = sss noautolegend;

label measure="Measure";

vbar id/response= value group=measure

BARWIDTH=1  NOOUTLINE;

yaxis values = (0 to 1 by 0.1);

run;

this created this graph:

I have to play with xaxis a bit more but this is already good.

This is actually plot produced from Structure software. Structure by itself creates this kinf of plots but they are in low resolution. This was created from Structure output.

Hope this will help someone

🔒 This topic is solved and locked.