[R] pcaMethods and Lattice help.

Peter Ehlers ehlers at ucalgary.ca
Mon Jul 19 18:24:49 CEST 2010


On 2010-07-19 7:35, Shawn Way wrote:
> I've been using the pcaMethods to develop a scores matrix
>
> =======================================
> data(iris)
> pcIr<- pca(iris[,1:4], method="nipals", nPcs=3, cv="q2")
>
> test<- scores(pcIr)
> ========================================
>
> What I'm looking to do is to use lattice's barchart to plot the scores
> something like below, but expanded to all the scores columns.  Can someone
> give me a clue?  I've thought about restructuring the data, but I'm not
> sure as to the best method to do this.  (This is an example only....)
>
> ===========================
>   barchart(test[,1],origin=0)
> ===========================

Here are a couple of ways:

#1
barchart(test, origin = 0, stack = FALSE)

#2
testdf <- stack(as.data.frame(test))
names(testdf) <- c("Scores", "PC")
testdf$idx <- gl(150, 1)
barchart(Scores ~ idx | PC, origin = 0, data = testdf, layout=c(1,3))

You might find

  dotplot(test)

useful, as well.

   -Peter Ehlers


> Thank you kindly,
>
> --------------------------------------------------------------
> Shawn Way, PE
> MECO, Inc.
> (p) 281-276-7612
> (f)  281-313-0248
>



More information about the R-help mailing list