Dear List Having not received any comments for or against my proposal to make screeplot() a generic function, I found some time to make the relevant changes to the svn trunk repository (revision 40848).
Please find attached a patch against the R svn trunk sources including changes to the relevant help files and NAMESPACE. This builds and passes make check-devel out of the box on my FC4 machine. I took the option of making the default method for screeplot the existing function and the plot methods for princomp and prcomp both call screeplot.default directly. This, I hope, preserves the current behaviour and should be backwards compatible with code/packages/examples/docs that use these functions. One alternative would be to have explicit methods for classes "prcomp" and "princomp" that extract the relevant variances and pass on to screeplot.default for plotting. If this is preferred I can provide a patch for this scenario for consideration? All the best, Gav On Fri, 2007-03-02 at 17:53 +0100, [EMAIL PROTECTED] wrote: > Full_Name: Gavin Simpson > Version: 2.5.0 > OS: Linux (FC5) > Submission from: (NULL) (128.40.33.76) > > > Screeplots are a common plot-type used to interpret the results of various > ordination methods and other techniques. A number of packages include > ordination > techniques not included in a standard R installation. screeplot() works for > princomp and prcomp objects, but not for these other techniques as it was not > designed to do so. The current situation means, for example, that I have > called > a function Screeplot() in one of my packages, but it would be easier for users > if they only had to remember to use screeplot() to generate a screeplot. > > I would like to request that screeplot be made generic and methods for prcomp > and princomp added to R devel. This way, package authors can provide screeplot > methods for their functions as appropriate. > > I have taken a look at the sources for R devel (from the SVN repository) in > file > princomp-add.R and prcomp.R and it looks a relatively simple change to make > screeplot generic. > > I would be happy to provide patches and documentation if R Core were > interested > in making this change - I haven't done this yet as I don't want to spend time > doing something that might not be acceptable to R core in general. > > Many thanks, > > G -- %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~% Gavin Simpson [t] +44 (0)20 7679 0522 ECRC [f] +44 (0)20 7679 0565 UCL Department of Geography Pearson Building [e] gavin.simpsonATNOSPAMucl.ac.uk Gower Street London, UK [w] http://www.ucl.ac.uk/~ucfagls/ WC1E 6BT [w] http://www.freshwaters.org.uk/ %~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
Index: /home/gavin/R/devel/src/library/stats/NAMESPACE =================================================================== --- /home/gavin/R/devel/src/library/stats/NAMESPACE (revision 40848) +++ /home/gavin/R/devel/src/library/stats/NAMESPACE (working copy) @@ -388,6 +388,7 @@ S3method(print, summary.princomp) S3method(reorder, dendrogram) S3method(rev, dendrogram) +S3method(screeplot, default) S3method(str, dendrogram) S3method(summary, prcomp) S3method(summary, princomp) Index: /home/gavin/R/devel/src/library/stats/R/prcomp.R =================================================================== --- /home/gavin/R/devel/src/library/stats/R/prcomp.R (revision 40848) +++ /home/gavin/R/devel/src/library/stats/R/prcomp.R (working copy) @@ -60,7 +60,7 @@ } plot.prcomp <- function(x, main = deparse(substitute(x)), ...) - screeplot(x, main = main, ...) + screeplot.default(x, main = main, ...) print.prcomp <- function(x, print.x = FALSE, ...) { cat("Standard deviations:\n") Index: /home/gavin/R/devel/src/library/stats/R/princomp-add.R =================================================================== --- /home/gavin/R/devel/src/library/stats/R/princomp-add.R (revision 40848) +++ /home/gavin/R/devel/src/library/stats/R/princomp-add.R (working copy) @@ -46,9 +46,11 @@ } plot.princomp <- function(x, main = deparse(substitute(x)), ...) - screeplot(x, main = main, ...) + screeplot.default(x, main = main, ...) -screeplot <- +screeplot <- function(x, ...) UseMethod("screeplot") + +screeplot.default <- function(x, npcs = min(10, length(x$sdev)), type = c("barplot", "lines"), main = deparse(substitute(x)), ...) Index: /home/gavin/R/devel/src/library/stats/man/screeplot.Rd =================================================================== --- /home/gavin/R/devel/src/library/stats/man/screeplot.Rd (revision 40848) +++ /home/gavin/R/devel/src/library/stats/man/screeplot.Rd (working copy) @@ -1,22 +1,23 @@ \name{screeplot} \alias{screeplot} -\title{Screeplot of PCA Results} +\alias{screeplot.default} +\title{Screeplots} \usage{ -screeplot(x, npcs = min(10, length(x$sdev)), +\method{screeplot}{default}(x, npcs = min(10, length(x$sdev)), type = c("barplot", "lines"), main = deparse(substitute(x)), \dots) } \arguments{ - \item{x}{an object of class \code{"princomp"}, as - from \code{\link{princomp}()}.} - \item{npcs}{the number of principal components to be plotted.} + \item{x}{an object containing a \code{sdev} component, such as that + returned by \code{\link{princomp}()} and \code{\link{prcomp}().} + \item{npcs}{the number of components to be plotted.} \item{type}{the type of plot.} \item{main, \dots}{graphics parameters.} } \description{ - \code{screeplot} plots the variances against the number of the - principal component. This is also the \code{plot} method for class - \code{"princomp"}. + \code{screeplot.default} plots the variances against the number of the + principal component. This is also the \code{plot} method for classes + \code{"princomp"} and \code{"prcomp"}. } \references{ Mardia, K. V., J. T. Kent and J. M. Bibby (1979). @@ -26,7 +27,7 @@ \emph{Modern Applied Statistics with S}, Springer-Verlag. } \seealso{ - \code{\link{princomp}}. + \code{\link{princomp}} and \code{\link{prcomp}}. } \examples{ ## The variances of the variables in the Index: /home/gavin/R/devel/src/library/stats/man/prcomp.Rd =================================================================== --- /home/gavin/R/devel/src/library/stats/man/prcomp.Rd (revision 40848) +++ /home/gavin/R/devel/src/library/stats/man/prcomp.Rd (working copy) @@ -114,7 +114,7 @@ \emph{Modern Applied Statistics with S}, Springer-Verlag. } \seealso{ - \code{\link{biplot.prcomp}}, + \code{\link{biplot.prcomp}}, \code{\link{screeplot}}, \code{\link{princomp}}, \code{\link{cor}}, \code{\link{cov}}, \code{\link{svd}}, \code{\link{eigen}}. }
______________________________________________ R-devel@r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel