diff --git a/R/createES.R b/R/createES.R index a9587dae6118ba2bb65d8e74e4982652c82cc5f2..4af168e7c3da479d94cc6249f47d995797851d43 100644 --- a/R/createES.R +++ b/R/createES.R @@ -1,5 +1,5 @@ createES <- function(data, pData, labelDescription, colNames, rowNames) { - exprs <- data + exprs <- t(data) colnames(exprs) <- colNames truePData <- pData pd <- data.frame(truePData, row.names = colNames) diff --git a/R/pcaPlot.R b/R/pcaPlot.R index 964f2500e677fa941f20400d50c1353341a81a66..d4646411b2f50f82b8fb803f3309859e265fe5e8 100644 --- a/R/pcaPlot.R +++ b/R/pcaPlot.R @@ -5,11 +5,13 @@ #' @examples #' pcaPlot(es.norm, 1, 2) + aes(color=time) #' @export -pcaPlot <- function(es, columns=c(), rows=c(), c1, c2, size="", colour="") { +pcaPlot <- function(es, columns=c(), rows=c(), c1, c2, size="", colour="", label="") { n1 <- as.numeric(c1) n2 <- as.numeric(c2) stopifnot(require(ggplot2)) + stopifnot(require(ggrepel)) stopifnot(require(Biobase)) + stopifnot(require(svglite)) if (is.null(rows)) { rows <- 1:nrow(exprs(es)) @@ -24,17 +26,17 @@ pcaPlot <- function(es, columns=c(), rows=c(), c1, c2, size="", colour="") { data <- t(exprs(es)[rows,columns]) pca <- prcomp(data) explained <- (pca$sdev)^2 / sum(pca$sdev^2) - + xs <- sprintf("PC%s", seq_along(explained)) xlabs <- sprintf("%s (%.1f%%)", xs, explained * 100) - + pData <- pData(es)[!(rownames(pData(es)) %in% setdiff(rownames(pData(es)), rownames(pca$x))),] if (size != "") { pData[[size]] <- as.numeric(pData[[size]]) } - pp <- ggplot(data=cbind(as.data.frame(pca$x), pData)) + pp <- ggplot(data=cbind(as.data.frame(pca$x), pData, sampleNames(es))) if (size != "" && colour != "") { aes <- aes_string(x=xs[n1], @@ -42,16 +44,32 @@ pcaPlot <- function(es, columns=c(), rows=c(), c1, c2, size="", colour="") { } else if (colour != "") { aes <- aes_string(x=xs[n1], - y=xs[n2], colour=colour) + y=xs[n2], colour=colour) } else if (size != "") { aes <- aes_string(x=xs[n1], - y=xs[n2], size=size) + y=xs[n2], size=size) } else { aes <- aes_string(x=xs[n1], y=xs[n2]) } - pp + - geom_point(aes) + + g <- pp + aes + + geom_point() + xlab(xlabs[n1]) + ylab(xlabs[n2]) + + if (label == "id") { + label <- "sampleNames(es)" + } + if (label != "") { + message("i'm here 2s") + g <- g + geom_text_repel(aes_string(label=label)) + + } + f <- tempfile(pattern="plot",tmpdir="~/morpheus.js/tmp",fileext=".svg") + ggsave(f, g) + + + + print(capture.output(str(g))) + return(f) }