2

I have modified the iris data to provide an example of what I would like to do. I add an extra column to the iris data as provided in the link below. This extra column has also some groups based on organs.

I then do the PCA and plot it. I would like to have two groups in the plot differentiated by color and shape. The organs are differentiated by four shapes but the species are not differentiated by color except for the blue color which is shown in the plot.

library(ggbiplot)

data(iris)

#### add an extra column with organ information

iris$organ<-c(rep("leaf",50),rep("root",50),rep("shrub",25),rep("petal",25))

# log transform 
log.ir <- log(iris[, 1:4])

#grouping by species
ir.species <- iris[, 5]

#grouping by organs
ir.organ <- iris[,6]

##PCA
ir.pca <- prcomp(log.ir, center = TRUE,scale. = TRUE) 

###PCA plots
g <- ggbiplot(ir.pca, obs.scale = 1, var.scale = 1,groups = ir.species)
g+geom_point(aes(shape=factor(ir.organ)))

PCA plot

user20650
  • 24,654
  • 5
  • 56
  • 91
Paul
  • 1,077
  • 3
  • 14
  • 27
  • I think your `geom_point` call is plotting black symbols on top of the colored ones that `ggbiplot` produces by default. You can add `col = ir.species` to the `aes` to get colors, but it still looks weird. – Axeman Oct 13 '15 at 17:31
  • 2
    `ggbiplot(ir.pca, obs.scale = 1, var.scale = 1, alpha=0) + geom_point(aes(shape=factor(ir.organ), colour=factor(ir.species)), size=4)` – user20650 Oct 13 '15 at 17:36

0 Answers0