Commit 37f09427 authored by Daria Zenkova's avatar Daria Zenkova

added support of size and colour in ggplot2

parent 71b2e93e
# Generated by roxygen2: do not edit by hand
export(pcaPlot)
export(createES)
\ No newline at end of file
createES <- function(data, pData, labelDescription, colNames, rowNames) {
exprs <- data
colnames(exprs) <- colNames
truePData <- t(pData)
pd <- data.frame(truePData, row.names = colNames)
names(pd) <- labelDescription
require(Biobase)
phenoData <- AnnotatedDataFrame(pd)
featureData <- AnnotatedDataFrame(data.frame(rowNames))
es <- ExpressionSet(assayData = exprs, phenoData=phenoData, featureData = featureData)
return(es)
}
\ No newline at end of file
......@@ -5,20 +5,39 @@
#' @examples
#' pcaPlot(es.norm, 1, 2) + aes(color=time)
#' @export
pcaPlot <- function(es, c1, c2) {
pcaPlot <- function(es, columns, c1, c2, size="", colour="") {
stopifnot(require(ggplot2))
pca <- prcomp(t(exprs(es)))
stopifnot(require(Biobase))
data <- t(exprs(es)[columns,])
pca <- prcomp(~., data.frame(data))
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)))
pData <- pData(es)[!(rownames(pData(es)) %in% setdiff(rownames(pData(es)), rownames(pca$x))),]
pp <- ggplot(data=cbind(as.data.frame(pca$x), pData))
if (size == "" && colour == "") {
aes <- aes(x=eval(parse(text=xs[c1])),
y=eval(parse(text=xs[c2])))
} else if (size == "" && colour != "") {
c <- pData[[colour]];
aes <- aes(x=eval(parse(text=xs[c1])),
y=eval(parse(text=xs[c2])), colour=c)
} else if (size != "" && colour == "") {
s <- pData[[size]];
aes <- aes(x=eval(parse(text=xs[c1])),
y=eval(parse(text=xs[c2])), size=s)
} else {
s <- pData[[size]]
c <- pData[[colour]]
aes <- aes(x=eval(parse(text=xs[c1])),
y=eval(parse(text=xs[c2])), colour=c,size=s)
}
pp +
geom_point(aes(x=eval(parse(text=xs[c1])),
y=eval(parse(text=xs[c2]))), size=3) +
geom_point(aes) +
xlab(xlabs[c1]) + ylab(xlabs[c2])
}
......@@ -5,8 +5,13 @@ SaveWorkspace: No
AlwaysSaveHistory: Default
EnableCodeIndexing: Yes
UseSpacesForTab: Yes
NumSpacesForTab: 2
Encoding: UTF-8
RnwWeave: Sweave
LaTeX: pdfLaTeX
AutoAppendNewline: Yes
StripTrailingWhitespace: Yes
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment