-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy pathplotCorrelation.R
48 lines (40 loc) · 1.52 KB
/
plotCorrelation.R
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# script to wrangle data and plot correlation
library(data.table)
library(dplyr)
library(tidyverse)
library(ggpubr)
library(ggforce)
library(ggplot2)
# function to wrangle data
dataWrangle <- function(data, mData){
df.name <- data %>%
rownames_to_column(var = 'gene') %>%
gather(key = 'sample', value = 'FPKM', -c(gene)) %>%
group_by(gene)
#mutate('mean_FPKM' = mean(FPKM)) %>%
#mutate('median_FPKM' = median(FPKM))
# merge with metadata
df.name <- merge(df.name, mData, by.x = 'sample', by.y = 'Title')
names(df.name)[4] <- 'MYCN_Status'
# get expression values for genes in genelist
res <- merge(genes8, df.name, by.x = 'V1', by.y = 'gene')
# reshaping data
res <- res %>%
spread(key = 'V1', value = 'FPKM') %>%
gather(key = 'gene', value = 'FPKM',-c(sample, MYCN_Status, MYCN, RISK))
return(res)
}
# function to plot data
plotCorr <- function(df,colorby) {
# plot correlation
ggplot(df, aes(x = MYCN, y = FPKM, color = eval(parse(text = colorby)))) +
geom_point() +
geom_smooth(method=lm, se=FALSE) +
xlab("MYCN expression") +
ylab("Gene expression") +
theme_bw() +
#stat_cor(method = "pearson", aes(label = paste(..r.label..,..rr.label..,..p.label.., sep = "~` `~` `~"))) +
stat_cor(method = "pearson", aes(label = paste(after_stat(r.label),after_stat(rr.label),after_stat(p.label), sep = "~` `~` `~"))) +
facet_wrap(. ~ gene, scales = "free") +
theme(strip.text = element_text(size=8), legend.position = "bottom", legend.title = element_text(size=5))
}