From 71b2e93e6bba813c4d5988cf132bef1894fdf7ea Mon Sep 17 00:00:00 2001 From: Daria Zenkova Date: Wed, 17 Aug 2016 15:38:16 +0300 Subject: [PATCH] fix commit --- R/pcaPlot.R | 24 ++++++++++++++++++++++++ man/pcaPlot.Rd | 22 ++++++++++++++++++++++ 2 files changed, 46 insertions(+) create mode 100644 R/pcaPlot.R create mode 100644 man/pcaPlot.Rd diff --git a/R/pcaPlot.R b/R/pcaPlot.R new file mode 100644 index 0000000..7a33e62 --- /dev/null +++ b/R/pcaPlot.R @@ -0,0 +1,24 @@ +#' Makes nice PCA plot for expression data +#' @param es an ExpressionSet object, should be normalized +#' @param c1 a number of the first component to plot (numeric) +#' @param c2 a number of the second component to plot (numeric) +#' @examples +#' pcaPlot(es.norm, 1, 2) + aes(color=time) +#' @export +pcaPlot <- function(es, c1, c2) { + stopifnot(require(ggplot2)) + pca <- prcomp(t(exprs(es))) + + + explained <- (pca$sdev)^2 / sum(pca$sdev^2) + + xs <- sprintf("PC%s", seq_along(explained)) + xlabs <- sprintf("%s (%.1f%%)", xs, explained * 100) + + pp <- ggplot(data=cbind(as.data.frame(pca$x), pData(es))) + + pp + + geom_point(aes(x=eval(parse(text=xs[c1])), + y=eval(parse(text=xs[c2]))), size=3) + + xlab(xlabs[c1]) + ylab(xlabs[c2]) +} diff --git a/man/pcaPlot.Rd b/man/pcaPlot.Rd new file mode 100644 index 0000000..7abd70a --- /dev/null +++ b/man/pcaPlot.Rd @@ -0,0 +1,22 @@ +% Generated by roxygen2: do not edit by hand +% Please edit documentation in R/pca_plot.R +\name{pcaPlot} +\alias{pcaPlot} +\title{Makes nice PCA plot for expression data} +\usage{ +pcaPlot(es, c1, c2) +} +\arguments{ +\item{es}{an ExpressionSet object, should be normalized} + +\item{c1}{a number of the first component to plot (numeric)} + +\item{c2}{a number of the second component to plot (numeric)} +} +\description{ +Makes nice PCA plot for expression data +} +\examples{ +pcaPlot(es.norm, 1, 2) + aes(color=time) +} + -- GitLab