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

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

library(ggplot2)

pca.data <- data.frame(Sample=rownames(pca$x),
                       X=pca$x[,1],
                       Y=pca$x[,2])
pca.data

ggplot(data=pca.data, 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 • 845 views
ADD COMMENTlink written 5 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 5 months ago by jrj.healey11k

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

ADD REPLYlink written 5 months ago by h.mon24k

You can just install the development version straight from GitHub:

devtools::install_github("vqv/ggbiplot")

Downloading GitHub repo vqv/ggbiplot@master
from URL https://api.github.com/repos/vqv/ggbiplot/zipball/master
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)

.

library(ggbiplot)
Carregando pacotes exigidos: ggplot2
Carregando pacotes exigidos: plyr
Carregando pacotes exigidos: scales
Carregando pacotes exigidos: grid

.

?ggbiplot
ggbiplot               package:ggbiplot                R Documentation

Biplot for Principal Components using ggplot2

Description:

     Biplot for Principal Components using ggplot2

Usage:

       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, ...)

Arguments:

   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 5 months ago by Kevin Blighe39k
Please log in to add an answer.

Help
Access

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