Re: [R] plotting prcomp

From: Gavin Simpson <gavin.simpson_at_ucl.ac.uk>
Date: Sat, 28 Jun 2008 12:25:51 +0100

On Fri, 2008-06-27 at 21:43 +0200, Dan Bolser wrote:
> 2008/6/27 Prof Brian Ripley <ripley@stats.ox.ac.uk>:
<snip />
> >
> > I forgot to answer that: just ask R to show you stats:::biplot.prcomp
>
> Ah! I never knew the ::: trick!

In this case you also need to know that biplot.prcomp is in stats. getAnywhere() is a more general solution:

getAnywhere(biplot.prcomp)

The following R News article by Uwe Ligges covers aspects of finding the sources for R functions:

Uwe Ligges. R help desk: Accessing the sources. R News, 6(4):43-45, October 2006.

HTH G

>
> I got it working after looking at the code -
>
>
> my.df <-
> data.frame(A=(x <- rnorm(100,mean=100, sd=10)),
> B=(y <- x + rnorm(100,mean=10, sd=10)))
>
> plot(my.df)
>
> my.pc <-
> prcomp(my.df, center=TRUE, scale=TRUE)
>
> biplot(my.pc)
>
> attributes(my.pc)
>
> head(scores <- my.pc$x)
>
> lam <- my.pc$sdev
>
> n <- nrow(my.pc$x)
>
> lam <- lam * sqrt(n)
>
> my.x <- (my.pc$x)[,1] / lam[1]
> my.y <- (my.pc$x)[,2] / lam[2]
>
> plot(my.x, my.y, type="n")
> text(my.x, my.y, labels=1:100)
>
>
>
> >>> What am I missing?
> >>
> >> Reading the references on ?biplot.prcomp, or a good book on the subject
> >> (such as MASS or Gower & Hand).
> >>
> >> A biplot is a specific type of plot and the help page does not spell out
> >> the rather mathematical details (and there are several variants).
> >>
> >>>
> >>> Dan.
> >>>
> >>> [[alternative HTML version deleted]]
> >>>
> >>> ______________________________________________
> >>> R-help_at_r-project.org mailing list
> >>> https://stat.ethz.ch/mailman/listinfo/r-help
> >>> PLEASE do read the posting guide
> >>> http://www.R-project.org/posting-guide.html
> >>> and provide commented, minimal, self-contained, reproducible code.
> >>>
> >>
> >> --
> >> Brian D. Ripley, ripley_at_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
> >>
> >
> > --
> > Brian D. Ripley, ripley_at_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
> >
>
>
>

-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Dr. Gavin Simpson             [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%

______________________________________________
R-help_at_r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.
Received on Sat 28 Jun 2008 - 11:30:41 GMT

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.2.0, at Sat 28 Jun 2008 - 15:00:51 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.

list of date sections of archive