Re: [R] Titles in plots generated within tapply

From: Christos Hatzis <christos_at_nuverabio.com>
Date: Thu 02 Feb 2006 - 18:28:57 EST


You were close with mapply. You can pass the labels as a second argument to your function
To take advantage of the vectorized nature of mapply:

mapply(function(x,y) barplot(table(x), xlab = 'Result', main=paste("Group",y,sep="-")),
 split(result, group), levels(group))

-Christos

-----Original Message-----
From: r-help-bounces@stat.math.ethz.ch
[mailto:r-help-bounces@stat.math.ethz.ch] On Behalf Of Dennis Malandro Sent: Thursday, February 02, 2006 1:35 AM To: R-help@stat.math.ethz.ch
Subject: [R] Titles in plots generated within tapply

How would one go about putting titles in each of several plots that are generated from within a call to tapply? For example I'd like the following two barplots to have titles 'Group 1' and 'Group 2', where '1' and '2' come from the levels of 'group'.

group <- gl(2, 10)
result <- sample(c('A', 'B'), size=length(group), replace=TRUE) windows(7, 4) par(mfrow = c(1, 2)) tapply(result, group,

       function(x) barplot(table(x), xlab = 'Result'))

I found something close to what I'm looking for here http://tolstoy.newcastle.edu.au/R/help/04/09/3219.html. So I tried

mapply(function(x) barplot(table(x), xlab = 'Result'),   split(result, group), main = levels(group))

Error in function (x) : unused argument(s) (main ...)

(I expected to get titles of '1' and '2'. Not exactly what I asked for in the question, but it would have been progress.)

Much obliged,
Dennis



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide!
http://www.R-project.org/posting-guide.html

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Feb 02 18:37:30 2006

This archive was generated by hypermail 2.1.8 : Thu 02 Feb 2006 - 20:22:50 EST