Skip to content

Instantly share code, notes, and snippets.

@sansense
sansense / biostars_244570.R
Created March 31, 2017 13:27
biostars_244570.R
set.seed(100)
d = data.frame(matrix(runif(150), nrow=30, ncol=5)) # 30 x 5 data from uniform distribution
colnames(d) = c("co1", "co2", "ca1", "ca2", "ca3") # 2 Controls / 3 Cancers
rownames(d) = paste0("g", 1:30) # gene names
## Case1: Principal componenets assuming samples (ca / co) as variables; The genes will get plotted on the PC-axes
## I've removed the loading levels for a clear picture.
head(d)
autoplot(prcomp(d),
@sansense
sansense / biostars_244570.R
Created March 31, 2017 13:27
biostars_244570.R
set.seed(100)
d = data.frame(matrix(runif(150), nrow=30, ncol=5)) # 30 x 5 data from uniform distribution
colnames(d) = c("co1", "co2", "ca1", "ca2", "ca3") # 2 Controls / 3 Cancers
rownames(d) = paste0("g", 1:30) # gene names
## Case1: Principal componenets assuming samples (ca / co) as variables; The genes will get plotted on the PC-axes
## I've removed the loading levels for a clear picture.
head(d)
autoplot(prcomp(d),
set.seed(100)
d = data.frame(matrix(runif(150), nrow=30, ncol=5)) # 30 x 5 data from uniform distribution
colnames(d) = c("co1", "co2", "ca1", "ca2", "ca3") # 2 Controls / 3 Cancers
rownames(d) = paste0("g", 1:30) # gene names
## Case1: Principal componenets assuming samples (ca / co) as variables; The genes will get plotted on the PC-axes
## I've removed the loading levels for a clear picture.
head(d)
autoplot(prcomp(d),
set.seed(100)
d = data.frame(matrix(runif(150), nrow=30, ncol=5)) # 30 x 5 data from uniform distribution
colnames(d) = c("co1", "co2", "ca1", "ca2", "ca3") # 2 Controls / 3 Cancers
rownames(d) = paste0("g", 1:30) # gene names
## Case1: Principal componenets assuming samples (ca / co) as variables; The genes will get plotted on the PC-axes
## I've removed the loading levels for a clear picture.
head(d)
autoplot(prcomp(d),
set.seed(100)
d = data.frame(matrix(runif(150), nrow=30, ncol=5)) # 30 x 5 data from uniform distribution
colnames(d) = c("co1", "co2", "ca1", "ca2", "ca3") # 2 Controls / 3 Cancers
rownames(d) = paste0("g", 1:30) # gene names
## Case1: Principal componenets assuming samples (ca / co) as variables; The genes will get plotted on the PC-axes
## I've removed the loading levels for a clear picture.
head(d)
autoplot(prcomp(d),
## Modified plotPCA from DESeq2 package. Shows the Names of the Samples (the first col of SampleTable), and uses ggrepel pkg to plot them conveniently.
# @SA 10.02.2017
library(genefilter)
library(ggplot2)
library(ggrepel)
plotPCA.san <- function (object, intgroup = "condition", ntop = 500, returnData = FALSE)
{
rv <- rowVars(assay(object))
select <- order(rv, decreasing = TRUE)[seq_len(min(ntop,