3

In my script for PCA (below), I always get a graph of PC1 vs PC2.

 mydata.pca <- prcomp(mydata.fixed, center = TRUE, scale. = TRUE)

 g <- ggbiplot(mydata.pca, obs.scale = 1, var.scale = 1, 
               groups = mysamples, ellipse = FALSE, 
               circle = FALSE, var.axes=FALSE) 
g <- g + scale_color_discrete(name = '') 
g <- g + theme(legend.direction ='horizontal', 
                legend.position = 'top') 
g <- g + theme_bw()

However, when I run something like:

summary(mydata.pca)

I see all the info for PC1 to PC4. How can I change my ggbioplot script to get a graph of PC1 vs PC3?

Chris
  • 6,302
  • 1
  • 27
  • 54
user5797184
  • 31
  • 1
  • 2

1 Answers1

4

The choices argument to ggbiplot is what you are looking for:

iris_pca <- prcomp(iris[, 1:4], center = TRUE, scale. = T)

# PC1 vs PC 2

ggbiplot(iris_pca, choices = c(1,2), obs.scale = 1, var.scale = 1, 
         groups = iris$Species, ellipse = TRUE, 
         circle = TRUE) + scale_color_discrete(name = '') + theme(legend.direction = 'horizontal', 
               legend.position = 'top')

enter image description here

# PC1 vs PC 3

ggbiplot(iris_pca, choices = c(1,3), obs.scale = 1, var.scale = 1, 
         groups = iris$Species, ellipse = TRUE, 
         circle = TRUE) + scale_color_discrete(name = '') + theme(legend.direction = 'horizontal', 
               legend.position = 'top')

enter image description here

Chris
  • 6,302
  • 1
  • 27
  • 54