title: Using PCA in R--Changing axes to remove columns
body: <p>I have the following code in R.  Briefly, I start with the iris data from <a href="https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data" rel="nofollow">https://archive.ics.uci.edu/ml/machine-learning-databases/iris/iris.data</a> .
  Then I want to perform principal component analysis on this dataset to end up with a two dimensional dataset that I can at the end make a scatterplot of the final data. I'm using the prcomp function to get the principal component, and taking the rotation from that. </p>
  
  <pre><code>irisdat &lt;- read.csv('iris.data', header=FALSE)
  library(lattice)
  library(stats)
  numiris=irisdat[,c(1,2,3,4)]
  pr=prcomp(numiris, center=TRUE, scale=TRUE)
  newdata = as.matrix(numiris) %*% pr$rotation
  pr2=prcomp(newdata, center=TRUE, scale=TRUE)
  newdata2 = as.matrix(newdata) %*% pr2$rotation
  </code></pre>
  
  <p>Now the problem that I have is that I just end up with a matrix that still has four dimensions when I want to get it down to two by the end but I'm not sure how to remove columns, or what to remove, after doing the principal component analysis projection.</p>
  
  <p>Also, I'm having a problem where my results are inverted from the original data so if I print out a scatterplot matrix with splom, the scatterplots are reversed.</p>
  
  <p>Any thoughts?</p>