Need help in R (Statistic Programe)

  • Thread starter Thread starter Philip Wong
  • Start date Start date
AI Thread Summary
The discussion focuses on using R to plot principal component (PC) scores with a group variable for visualization. The user has loaded the MASS library, imported a dataset, and performed a log transformation to address skewness. They seek clarification on how to properly factorize the group variable for plotting and whether their commands for printing the first two PC components are correct. The user is uncertain about the expected output and is considering alternative commands for better visualization of the scores. Overall, the thread highlights challenges in using R for PCA plotting and seeks guidance on best practices.
Philip Wong
Messages
95
Reaction score
0
hello,
ok here is the situation, I wanted use R to plot a PC scores using a group variable (which is an external variable) as the plotting score. the command for printing the PC scores is prin$x. Below is some steps I've took so far:

> library(MASS) //loading the library called MASS
> island.df=read.csv(file.choose(),header=T) //feeding in the data file I want to do analyze on
> log.island.df=log((island.df[,4:10])+1) //log transform my data, because it was skewed
> x=island.df //rename my data into x, for easier used future
> prin=princomp(x[,4:10])
> scores=(x~as.factor(group)) //factorize the group variable as the plotting symbol, IS THIS HOW I DO IT? Is there other ways?
> prin$scores[,1:2] //I just want to print the first 2 components.IS this right? did I do something wrong? because I got no clue how the printout should looks like, so I don't know have I done it right or not!
 
Physics news on Phys.org
Or would it be better to use the following command if I want to use the group variable as the plotting symbol:
eqscplot(prin$scores[,1:2],type="n")
text(prin$scores[,1:2],label=as.vector(names))instead of just:
> prin$scores[,1:2] //I just want to print the first 2 components.
 
Last edited:

Similar threads

Back
Top