forked from kpatel427/YouTubeTutorials
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvisualize_ggplot2.R
61 lines (44 loc) · 1.37 KB
/
visualize_ggplot2.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
49
50
51
52
53
54
55
56
57
58
59
60
# script to visualize gene expression data (GSE183947)
# setwd("~/Desktop/demo/data_manipulation_R/scripts")
# load libraries
library(tidyverse)
library(ggplot2)
# data
# dat.long to be used generated from previous demo
# dat.long <- read.delim('../data/GSE183947_long_format.txt', header = T)
#basic format for ggplot
# ggplot(data, aes(x = variable, y = variable1)) +
# geom_col()
# 1. barplot
dat.long %>%
filter(gene == 'BRCA1') %>%
ggplot(., aes(x = samples, y = FPKM, fill = tissue)) +
geom_col()
# 2. density
dat.long %>%
filter(gene == 'BRCA1') %>%
ggplot(., aes(x = FPKM, fill = tissue)) +
geom_density(alpha = 0.3)
# 3. boxplot
dat.long %>%
filter(gene == 'BRCA1') %>%
ggplot(., aes(x = metastasis, y = FPKM)) +
#geom_boxplot()
geom_violin()
# 4. scatterplot
dat.long %>%
filter(gene == 'BRCA1' | gene == 'BRCA2') %>%
spread(key = gene, value = FPKM) %>%
ggplot(., aes(x = BRCA1, y = BRCA2, color = tissue)) +
geom_point() +
geom_smooth(method = 'lm', se = FALSE)
# 5. heatmap
genes.of.interest <- c('BRCA1', 'BRCA2', 'TP53', 'ALK', 'MYCN')
pdf("heatmap_save2.pdf", width = 10, height = 8)
dat.long %>%
filter(gene %in% genes.of.interest) %>%
ggplot(., aes(x = samples, y = gene, fill = FPKM)) +
geom_tile() +
scale_fill_gradient(low = 'white', high = 'red')
dev.off()
#ggsave(p, filename = 'heatmap_save1.pdf', width = 10, height = 8)