Nikos,
I think you can just replace the line
pc <- princomp(x[,1:2], scores=TRUE, na.action=na.fail)
with
pc <- prcomp(x[,1:2], retx=TRUE, center=pc.center,
scale.=pc.scale, na.action=na.fail)
and rename the components of pc
names(pc) <- c('sdev', 'loadings', 'center', 'scale', 'scores')
and then use the rest of the plotpc() code as is (except for
maybe having to use flip1=TRUE, etc).
As to why other functions used in plotpc() are not printed
when you ask R to print plotpc(): why should they be? Can you
imagine the mess that would result if you got the printouts of
is.na(), pushViewport, popViewport, ...? Egad!
Anyway, as you've discovered, when you want to modify code, look
at the sources.
-Peter Ehlers
On 2010-05-16 12:05, Nikos Alexandris wrote:
Nikos Alexandris:
Among the (R-)tools, I've seen on the net, for (bivariate) Principal
Component scatter plots (+histograms), "plotpc" [1] is the one I like
most.
[...]
I started the modification by attempting first to get a "prcomp" version of
"plotpc()" (named it "plotpc.svd()") by altering the following:
[...]
I am bit lost now about where I should continue looking for required
modifications in the code. Any hints?
Once again I am replying to myself ;-)
I've spend many-many hours of searching in manuals, on the net and trying
crazy things to understand where this mystical (to me) function "un()" could
be sourced from. Eventually I decided to change all of its occurrences with
"unit()" as I am sure this was the function meant to be used but I hit another
wall, another unknown function my.plot.something(). I was then sure that they
are "sourced" from somewhere.
At some point I was enlightened and had a look in the source "plotpc.R" where
I just found what I was expecting to found ;-). It may look silly but to the
unexperienced useR it is not. I was only looking at the print-out of "plotpc"
(without the parentheses) and was puzzled that the "un()" function is nowhere.
- Question: why isn't the whole source of plotpc.R printed out with
"plotpc"? Or why isn't any clue given where this "un()" function is coming
from? "methods()" and "getAnywhere()" say anything about it.
* Note to self: look at the Source.R
Anyhow, it was a long learning-night-session and I am good to go. In fact, I
am very close to what I want to do. I've added the option to use either
"prcomp" or "princomp" as well as if the input dataset should be centered
and/or scaled. I have still some strange issue with respect to how the plotted
histograms (of PC1 and PC2) along with their text are flipped. Hopefully I'll
fix this too.
I will be contacting soon the author to post him my modifications as
enhancement wishes. If anybody is interested to know or help please post here.
Regards, Nikos
______________________________________________
R-help@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.
--
______________________________________________
R-help@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.