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

2004-04-16 Thread David Whiting
Martin Maechler [EMAIL PROTECTED] writes:

 and I like to help you.
 As I keep installed `(almost) all released versions of R ever
 installed on our machines'
 I can easily run 1.8.1 (or 1.4.x or 1.0.x ...) for you.
 
 The only difference
  between the help page help(tapply)
 is an extra   require(stats) statement at the beginning of the
 `Examples' section in 1.9.0.
 
 and the only change to  tapply() is 
 group - rep.int(one, nx)#- to contain the splitting vector
 instead of
 group - rep(one, nx)#- to contain the splitting vector
 
 which hardly should have adverse results.
 
 In barplot, there's the new 'offset' option  --- not in NEWS ()
 
 and another change that may be a problem.
 
 Can you dig harder and if possible provide a reproducible (small..)
 example to make progress here...
 

Last night I found I had a backup of the source of 1.8.0, built that
and tested an example and it worked as in 1.9.0.  I then started to
question my sanity (or at least my competence).

The code that follows should be a reproducible example.  It creates a
data frame that has the same structure as the data I am working with
(with a number of other columns dropped) and is followed by the
function that creates the barplot.  The changes I have had to make to
make it work as I thought it was working with 1.8.1 have ## NEW BIT
after them, i.e. those lines were not there in the version I ran with
1.8.1.  The important new lines are:

 x - matrix(x)  ## NEW BIT

and 

 beside = TRUE,  ## NEW BIT



--- EXAMPLE ---

## Create some fake data.
x - c(rep(, 926), 
rep(All Other Perinatal Causes, 46), 
rep(Anaemia, 3), 
rep(Congenital Abnormalities, 1), 
rep(Unsp. Direct Maternal Causes, 24))
y - runif(length(x))
tempdat - data.frame(smi=x, yllperdth=y)



## Define the function to make my barplot
bodShare - function(x, fld, main = , userpar = 18, xlimMult=1.3 ) {
  ###
  # A horizontal barchart to display BoD shares #
  ###
  z - subset(x, as.character(x[,fld]) != )
  z[, fld] - factor(z[, fld])

  ## We need to change the parameters of the chart.
  ## First save the old settings.
  oldpar - par(mar)
  newpar - par(mar)

  ## Increase the size of the margin on the left so there 
  ## is enough space for the long text labels (which will 
  ## be displayed horizontally on the y-axis).
  newpar[2] - userpar

  
  ## Reduce the top margin because I will use a \caption in LaTeX 
  ## instead.
  newpar[3] - 1


  ## Now apply the new settings.
  par(mar = newpar)

  ## 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, 
##   main = main,
   horiz = TRUE, 
   beside = TRUE,## NEW BIT
   names.arg = causeNames,   ## NEW BIT
   xlab = Percent of YLLs,
   xlim = c(0, max(x) * xlimMult), 
   las = 1)
  
  text(x + (max(x) * .15), xplot, formatC(x, digits=1, format='f'))

  ## Reset the old margin parameters.
  par(mar = oldpar)
  
  ## Write data to a table for export.
  # First we need to remove newlines from labels.
  names(x) - sub(\n, , names(x))
  write.table(as.table(x), file = paste(tables/, fld, .csv, sep=), col.names=NA, 
sep=\t)
  names(x) - causeNames
  x[length(x)]
}

## Create the barplot.
bodShare(tempdat, smi)


-- 
David Whiting
Dar es Salaam, Tanzania

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


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

2004-04-15 Thread David Whiting

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
major1
minor9.0  
year 2004 
month04   
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  
major1
minor8.1  
year 2004 
month02   
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

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


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

2004-04-15 Thread Martin Maechler
 David == David Whiting [EMAIL PROTECTED]
 on 15 Apr 2004 11:42:18 + writes:

David Hi,

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

and I like to help you.
As I keep installed `(almost) all released versions of R ever
installed on our machines'
I can easily run 1.8.1 (or 1.4.x or 1.0.x ...) for you.

The only difference
 between the help page help(tapply)
is an extra   require(stats) statement at the beginning of the
`Examples' section in 1.9.0.

and the only change to  tapply() is 
group - rep.int(one, nx)#- to contain the splitting vector
instead of
group - rep(one, nx)#- to contain the splitting vector

which hardly should have adverse results.

In barplot, there's the new 'offset' option  --- not in NEWS ()

and another change that may be a problem.

Can you dig harder and if possible provide a reproducible (small..)
example to make progress here...


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

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

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

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

David Old version (as used with R 1.8.1):

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


David New Version (as used with R 1.9.0):

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

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

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




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


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

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

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

David Thanks.

David Dave

David -- David Whiting Dar es Salaam, Tanzania

__
[EMAIL PROTECTED] mailing list

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

2004-04-15 Thread Duncan Murdoch
On Thu, 15 Apr 2004 18:10:27 +0200, Martin Maechler
[EMAIL PROTECTED] wrote :

 David == David Whiting [EMAIL PROTECTED]
 on 15 Apr 2004 11:42:18 + writes:

David Hi,

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

and I like to help you.
As I keep installed `(almost) all released versions of R ever
installed on our machines'
I can easily run 1.8.1 (or 1.4.x or 1.0.x ...) for you.

The only difference
 between the help page help(tapply)
is an extra   require(stats) statement at the beginning of the
`Examples' section in 1.9.0.

and the only change to  tapply() is 
group - rep.int(one, nx)#- to contain the splitting vector
instead of
group - rep(one, nx)#- to contain the splitting vector

which hardly should have adverse results.

In barplot, there's the new 'offset' option  --- not in NEWS ()

and another change that may be a problem.

Here's a reproducible bug in barplot in 1.9.0 (based on an email I got
this morning from Richard Rowe):

x - table(rep(1:5,1:5))
barplot(x)

The problem is that table() produces a one dimensional array, and
barplot() doesn't handle those properly now.  The offending line is
this one:

$ cvs diff -r 1.3 barplot.R
[junk deleted] 
43c43
   width - rep(width, length.out = NR * NC)
---
   width - rep(width, length.out = NR)

In the example above, x gets turned into a matrix with NR=1 row and
NC=5 columns so only one bar width gets set.

Duncan Murdoch

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