Question: adding PCA ellipses on ggplot2
gravatar for demoraesdiogo2017
18 months ago by
demoraesdiogo201710 wrote:

Hello I have used the following code to generate a PCA graph of my data

library(ggplot2) <- data.frame(Sample=rownames(pca$x),

ggplot(, aes(x=X, y=Y, label=Sample)) +
  geom_text() +
  xlab(paste("PC1 - ", pca.var.per[1], "%", sep="")) +
  ylab(paste("PC2 - ", pca.var.per[2], "%", sep="")) +
  theme_bw() +
  ggtitle("Cancer studies PCA")

But was unable to add ellipses to it. Most tutorials I have seem have used ggbiplot for ellipses, and for some reason I'm unable to download this package (it says it doesn't exist).

What can I do?

rna-seq pca ggplot2 gene • 2.9k views
ADD COMMENTlink written 18 months ago by demoraesdiogo201710

Are you sure it says the package doesn’t exist, or just isn’t available for your R version etc?

ADD REPLYlink written 18 months ago by Joe16k

How are you trying to install ggplot2? Could you also post the results of sessionInfo()?

ADD REPLYlink written 18 months ago by h.mon29k

You can just install the development version straight from GitHub:


Downloading GitHub repo vqv/ggbiplot@master
from URL
Installing ggbiplot
* installing *source* package ‘ggbiplot’ ...
** R
** data
** byte-compile and prepare package for lazy loading
** help
*** installing help indices
** building package indices
** testing if installed package can be loaded
* DONE (ggbiplot)


Carregando pacotes exigidos: ggplot2
Carregando pacotes exigidos: plyr
Carregando pacotes exigidos: scales
Carregando pacotes exigidos: grid


ggbiplot               package:ggbiplot                R Documentation

Biplot for Principal Components using ggplot2


     Biplot for Principal Components using ggplot2


       ggbiplot(pcobj, choices = 1:2, scale = 1, pc.biplot =
       TRUE, obs.scale = 1 - scale, var.scale = scale, groups =
       NULL, ellipse = FALSE, ellipse.prob = 0.68, labels =
       NULL, labels.size = 3, alpha = 1, var.axes = TRUE, circle
       = FALSE, circle.prob = 0.69, varname.size = 3,
       varname.adjust = 1.5, varname.abbrev = FALSE, ...)


   pcobj: an object returned by prcomp() or princomp()

 choices: which PCs to plot

   scale: covariance biplot (scale = 1), form biplot (scale = 0). When
          scale = 1, the inner product between the variables
          approximates the covariance and the distance between the
          points approximates the Mahalanobis distance.

obs.scale: scale factor to apply to observations

var.scale: scale factor to apply to variables

pc.biplot: for compatibility with biplot.princomp()

  groups: optional factor variable indicating the groups that the
          observations belong to. If provided the points will be
          colored according to groups

 ellipse: draw a normal data ellipse for each group?
ADD REPLYlink written 18 months ago by Kevin Blighe56k
Please log in to add an answer.


Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1114 users visited in the last hour