Re: [R] Titles in plots generated within tapply

From: Prof Brian Ripley <ripley_at_stats.ox.ac.uk>
Date: Thu 02 Feb 2006 - 18:03:11 EST

On Wed, 1 Feb 2006, Dennis Malandro wrote:

> 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'))

You don't need tapply here (it is just lapply on split). Try

X <- split(result, group)
for(i in levels(group))

     barplot(table(X[[i]]), xlab = 'Result', main = paste("Group", i))

You could use lapply() rather than for(), but there would be no benefit.

-- 
Brian D. Ripley,                  ripley@stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595

______________________________________________
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:15:52 2006

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