adding PCA ellipses on ggplot2
0
0
Entering edit mode
6.2 years ago

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?

gene RNA-Seq ggplot2 pca • 8.4k views
ADD COMMENT
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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

ADD REPLY
0
Entering edit mode

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 REPLY

Login before adding your answer.

Traffic: 2369 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6