[R] tapply() and barplot() help files for 1.8.1

David Whiting david.whiting at ncl.ac.uk
Thu Apr 15 13:42:18 CEST 2004


Hi,

I've just upgraded to 1.9.0 and one of my Sweave files that produces a
number of barplots in a standard manner now produces them in a
different way.  I have made a couple of small changes to my code to
get the back the output I was getting before upgrading and now (mostly
out of curiosity) would like to understand what has changed.

I *think* I've tracked it down to tapply() and/or barplot() and have
not seen anything in the NEWS file regarding changes to these
functions (as far a I can see).  As part of doing my homework, I would
like to read the version 1.8.1 help files for these two functions, but
now that I've upgraded I'm not sure where I can find them.  Is there a
simple way for me to get copies of these two help files to compare
with the versions in 1.9.0?  As far as I can see, barplot() and
tapply() in 1.9.0 work as described in their 1.9.0 help files (which
does not surprise me).

I've been lurking on this list long enough to know that if there has
been a change it is documented, so it must be that I just haven't
found it yet.  If there hasn't been a change, then I am totally
perplexed, because I have been running this Sweave file several times
a day for the last few weeks and have not changed that part of it
(I've been changing the LaTeX parts).

In the part of the code that has changed I use tapply() to summarise
some data and then plot it with barplot().  I now have to use matrix()
on the output of tapply() before using barplot() because tapply()
produces a list and barplot() wants a vector or matrix.

In the code below, z is a dataframe, yllperdth is a numeric and fld
is the name of a factor, both in the dataframe.

Old version (as used with R 1.8.1):

  ## Calculate the % of YLLs for each group in the cause classification.
  x <- tapply(z$yllperdth, z[, fld], sum)
  totalYLLs <- sum(x)
  x <- x / totalYLLs * 100
  x <- sort(x)
  
  ## Plot the chart. horiz = TRUE makes it a bar instead of 
  ## column chart.  las = 1 prints the labels horizontally.
  xplot <- barplot(x, 
                   horiz = TRUE, 
                   xlab = "Percent of YLLs",
                   las = 1)


New Version (as used with R 1.9.0):

  ## Calculate the % of YLLs for each group in the cause classification.
  x <- tapply(z$yllperdth, z[, fld], sum)
  totalYLLs <- sum(x)
  x <- x / totalYLLs * 100
  x <- sort(x)

  causeNames <- names(x)  ## NEW BIT
  x <- matrix(x)          ## NEW BIT
  

  ## Plot the chart. horiz = TRUE makes it a bar instead of 
  ## column chart.  las = 1 prints the labels horizontally.
  xplot <- barplot(x, 
                   beside = TRUE,           ## NEW BIT
                   names.arg = causeNames,  ## NEW BIT
                   horiz = TRUE, 
                   xlab = "Percent of YLLs",
                   las = 1)




> version
         _                
platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
status                    
major    1                
minor    9.0              
year     2004             
month    04               
day      12               
language R                


A little while before upgrading I noted my previous R version (for a
post that I redrafted 7 times and never sent because I found the answer
through refining my draft), and it was:

> version
         _                
platform i686-pc-linux-gnu
arch     i686             
os       linux-gnu        
system   i686, linux-gnu  
status   Patched          
major    1                
minor    8.1              
year     2004             
month    02               
day      16               
language R                


So, can I get the old help files?  Or it is easy to point me to a
documented change?  Or is it clear from my code what has changed or
what I am or was doing wrong?

Thanks.

Dave

-- 
David Whiting
Dar es Salaam, Tanzania




More information about the R-help mailing list