Making MDS plot
2
0
Entering edit mode
liujy4 • 0
@6af711a0
Last seen 18 months ago
United States

Hi there,

I'm using EdgeR to analyze my RNAseq data. I have 2 questions: 1) It seems normLibSizes() does similar job as calcNormFactors (I've checked). What difference do they make, and under what situation?

2) I've got a MDS graph with colored labels on the plot. But I wanted to make a MDS plot showing colored shapes (i.e., dots and squares) with a label legend.

My metadata would look like:

sample  var time
JB0-1   JB  0h
JB0-2   JB  0h
JB0-3   JB  0h
JB10-1  JB  10h
JB10-2  JB  10h
JB10-3  JB  10h
...
LP0-1   LF  0h
LP0-2   LF  0h
LP0-3   LF  0h
LP10-1  LF  10h
LP10-2  LF  10h
LP10-3  LF  10h
...

Your kind help will be highly appreciated!

Jay


x <- read.csv(file="JB_LF.csv", header = TRUE, row.names = 1)
x <- as.matrix(x) # coerce to be matrix

# data has 2 var (LB vs LP) on 9 timepoints (0~8) with 3 reps)
group <- scan(text="JB0 ... JB8 ... LP0 ... LP8",  what="") 
group <- factor(group)

y <- DGEList(counts=x, group=group)
y$samples

# filter out genes with low counts
keep <- filterByExpr(y, group=group)
y_filter <- y[keep, , keep.lib.sizes=FALSE]

# TMM
y_filter_norm <- calcNormFactors(y_filter)
y_filter_norm$samples

# calculate CPM 
cpm_counts<-cpm(y_filter_TMM, normalized.lib.sizes = T)
write.csv(cpm_counts, file = "JB_LF_NormCPM_filter.csv")

# plot MDS
col <- as.numeric(group)
plotMDS(cpm_counts, col = col)
plotMDS limma • 3.5k views
ADD COMMENT
1
Entering edit mode
ATpoint ★ 4.6k
@atpoint-13662
Last seen 1 day ago
Germany

The two functions are synonyms, hence the same: https://bioconductor.org/packages/release/bioc/news/edgeR/NEWS

Use plot=FALSE with plotMDS() to return the data. You can use the $x/$y slots to plot the data with any color and aesthetics you like. A ggplot tutorial is recommended.

ADD COMMENT
0
Entering edit mode
@gordon-smyth
Last seen 25 minutes ago
WEHI, Melbourne, Australia

The secret to learning and using the enormous capabilities of R is to make regular use of the online help system. To check what normLibSizes() does, just type ?normLizSizes or ?calcNormFactors and it says

normLibSizes is the new name for calcNormFactors. The two functions are equivalent but calcNormFactors will eventually be retired.

On my computer, I have R set up so that each R help page opens up in a new browser Window, which makes for easy reading of long pages. The default R Studio setup is much more restrictive, but reading the help pages is still easy enough.

plotMDS has full capabilities to plot any shapes, any colors and to add legends. It uses the same syntax as the plot() function in R. Anything that works for plot will also work for plotMDS. To see what shapes are available, just type ?points.

Here is an example with colored dots and squares:

library(limma)
y <- matrix(rnorm(1000*6), 1000, 6)
Shape <- c(15,15,15,16,16,16)
Color <- c("blue","blue","blue","red","red","red")
plotMDS(y, col=Color, pch=Shape)
legend("topright", col=c("blue","red"), pch=c(15,16), legend=c("Group A","Group B"))
ADD COMMENT
0
Entering edit mode

Thank you so much! Your advice on becoming good at R is definitely true!

ADD REPLY

Login before adding your answer.

Traffic: 482 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