s-news
[Top] [All Lists]

Re: Grouping barplot, y axis in percent

To: s-news@lists.biostat.wustl.edu
Subject: Re: Grouping barplot, y axis in percent
From: Mario Cortina Borja <M.Cortina@ich.ucl.ac.uk>
Date: Mon, 10 Oct 2005 10:20:47 +0100
Cc: Patrick.Heer@bakom.admin.ch
In-reply-to: <972231170C40FE4797E048E1E39B22AB1EF87C@sbem35exc1004.efd.i ntra.admin.ch>
Hi Patrick,

One solution is as follows:

### suppose data.frame test has columns Sex and Age

mat1<- table( test$Sex, test$Age)
for(i in 1:2) mat1[i,]<- mat1[i,] / sum(mat1[i,])
barplot( mat1, beside=T, space=c(0,1), density=c(0,0), legend=levels(test$Sex),
col=c(1,5))
mtext(levels(test$Age), side=1, line=1, at=seq(2,20, by=3))
title(ylab='% Sex',xlab='Age groups')


Best wishes,

Mario


At 10:33 AM 10/10/2005 +0200, you wrote:
Dear all
Using S-Plus 6.0 for Windows XP

I am using a dataframe with numerous factor variables.
I'd like to plot, for example, a grouping barplot showing variable Sex
(2 categories) in percent for each Age (6 categories).

The data look the following way:

Sex     Age
Man     0-20
Woman   21-30
Man     21-30
Man     65+
...

PS: I tried to use the cross tab function, but it is veray expensive in
coding

Thanks in advance
Patrick
--------------------------------------------------------------------
This message was distributed by s-news@lists.biostat.wustl.edu.  To
unsubscribe send e-mail to s-news-request@lists.biostat.wustl.edu with
the BODY of the message:  unsubscribe s-news

_______________________
Dr Mario Cortina Borja
Senior Lecturer in Statistics
M.Cortina@ich.ucl.ac.uk  Phone +44(0)20 7905 2113 Fax +44(0)20 7905 2381
Paed. Epid. & Biostats, Institute of Child Health, UCL, London WC1N 1EH, UK

<Prev in Thread] Current Thread [Next in Thread>