Load libraries
if(!"scales" %in% row.names(installed.packages())){install.packages("scales")}
library(tidyverse)
## ── Attaching packages ─────────────────────────────────────── tidyverse 1.3.2 ──
## ✔ ggplot2 3.3.6 ✔ purrr 0.3.4
## ✔ tibble 3.1.8 ✔ dplyr 1.0.9
## ✔ tidyr 1.2.0 ✔ stringr 1.4.0
## ✔ readr 2.1.2 ✔ forcats 0.5.1
## ── Conflicts ────────────────────────────────────────── tidyverse_conflicts() ──
## ✖ dplyr::filter() masks stats::filter()
## ✖ dplyr::lag() masks stats::lag()
if(!"scales" %in% row.names(installed.packages())){install.packages("scales")}
library(scales)
##
## Attaching package: 'scales'
##
## The following object is masked from 'package:purrr':
##
## discard
##
## The following object is masked from 'package:readr':
##
## col_factor
Load data
load("../runs/kallisto_combined/mothertableV3.Rdata")
# View(dfr)
gene_set <- c("AT1G29930", "AT4G23230", "AT1G01120", "AT1G06410", "AT2G25510")
dir.create("../runs/guess_the_plots/", showWarnings = F, recursive = T)
Dot plot of individual tpm
plot_tpm <- subset(dfr, locus %in% gene_set,
select = c("locus", grep("_tpm", colnames(dfr), value = T)), drop = T)
plot_tpm <- pivot_longer(plot_tpm, cols = 2:ncol(plot_tpm))
plot_tpm$condition <- gsub("._tpm", "", plot_tpm$name)
p_tpm_point <- ggplot(plot_tpm, aes(x = locus, y = value)) +
geom_point(aes(col = condition), position = position_dodge(width = 0.5)) +
theme_classic() + scale_color_brewer(palette = "Dark2") +
labs(y = "Transcript level [tpm]")
print(p_tpm_point)

pdf(file = "../runs/guess_the_plots/p_tpm_point.pdf", width = 6, height = 6)
print(p_tpm_point)
print(p_tpm_point + labs(y = "") + theme(legend.position = "none"))
dev.off()
## quartz_off_screen
## 2
Bar plot of mean tpm
plot_tpm_mean <- subset(dfr, locus %in% gene_set,
select = c("locus", grep("mean_", colnames(dfr), value = T)), drop = T)
plot_tpm_mean <- pivot_longer(plot_tpm_mean, cols = 2:ncol(plot_tpm_mean))
plot_tpm_mean$condition <- gsub("mean_", "", plot_tpm_mean$name)
p_mean_bar <- ggplot(plot_tpm_mean, aes(x = locus, y = value)) +
geom_col(aes(fill = condition), position = position_dodge()) +
theme_classic() + scale_fill_brewer(palette = "Dark2") +
labs(y = "Transcript level [tpm]") +
scale_y_continuous(expand = expansion(mult = c(0, .1)))
print(p_mean_bar)

pdf(file = "../runs/guess_the_plots/p_mean_bar.pdf", width = 6, height = 6)
print(p_mean_bar)
print(p_mean_bar + labs(y = "") + theme(legend.position = "none"))
dev.off()
## quartz_off_screen
## 2
… log10 scaled
p_mean_bar_log10 <- p_mean_bar + scale_y_log10(breaks = trans_breaks("log10", function(x) 10^x),
labels = trans_format("log10", math_format(10^.x)),
expand = expansion(mult = c(0, .1)))
## Scale for 'y' is already present. Adding another scale for 'y', which will
## replace the existing scale.
print(p_mean_bar_log10) + annotation_logticks(sides = "l")


pdf(file = "../runs/guess_the_plots/p_mean_bar_log10.pdf", width = 6, height = 6)
print(p_mean_bar_log10) + annotation_logticks(sides = "l")
print(p_mean_bar_log10 + labs(y = "") + theme(axis.ticks.y = element_blank(), axis.text.y = element_blank()))
dev.off()
## quartz_off_screen
## 2
… facetted by gene locus
p_mean_bar_facet <- p_mean_bar + facet_wrap(~locus, scales = "free") +
theme(aspect.ratio = 1) +
theme(axis.text.x = element_blank(),
axis.ticks.x = element_blank(),
axis.title.x = element_blank())
print(p_mean_bar_facet)

pdf(file = "../runs/guess_the_plots/p_mean_bar_facet.pdf", width = 6, height = 6)
print(p_mean_bar_facet)
dev.off()
## quartz_off_screen
## 2
Heatmap of mean tpm
p_mean_heat <- ggplot(plot_tpm_mean, aes(x = condition, y = locus, fill = value)) +
geom_point(alpha = 1, size = 12, shape = 22) +
scale_x_discrete(position = "top") +
theme_classic() +
theme(aspect.ratio = length(gene_set), axis.title = element_blank(),
axis.text.x.top = element_text(angle = 45, hjust = 0),
axis.line = element_blank(),
axis.ticks = element_blank()) +
labs(fill = "Transcript level [tpm]")
p_mean_heat + scale_fill_gradient2(low = "white", high = "#C21F3A")

pdf(file = "../runs/guess_the_plots/p_mean_heat.pdf", width = 6, height = 5)
print(p_mean_heat + scale_fill_gradient2(low = "white", high = "#C21F3A"))
print(p_mean_heat + scale_fill_gradient2(low = "white", high = "#C21F3A") +
theme(legend.position = "none", axis.text.x.top = element_blank()))
dev.off()
## quartz_off_screen
## 2
…log10 scaled
p_mean_heat_log10 <- p_mean_heat + scale_fill_gradient2(low = "white", high = "#C21F3A", trans='log10') +
labs(fill = "log10(Transcript level [tpm])")
pdf(file = "../runs/guess_the_plots/p_mean_heat_log10.pdf", width = 6, height = 5)
print(p_mean_heat_log10)
print(p_mean_heat_log10 + theme(legend.position = "none"))
dev.off()
## quartz_off_screen
## 2
Bar plot of logFC
plot_logfc <- subset(dfr, locus %in% gene_set,
select = c("locus", "log2FC"), drop = T)
p_logfc_bar <- ggplot(plot_logfc, aes(x = locus, y = log2FC)) +
geom_col(width = 0.5) +
theme_classic() +
theme(aspect.ratio = length(gene_set)*0.7, axis.text.x = element_text(angle = 45, hjust = 1)) +
geom_hline(yintercept = 0) +
labs(y = "log2-FC (treatment/mock)")
print(p_logfc_bar)

pdf(file = "../runs/guess_the_plots/p_logfc_bar.pdf", width = 6, height = 6)
print(p_logfc_bar)
print(p_logfc_bar + labs(y = ""))
dev.off()
## quartz_off_screen
## 2
Heatmap of logFC
p_logfc_heat <- ggplot(plot_logfc, aes(x = 1, y = locus, fill = log2FC)) +
scale_fill_gradient2(low = "#377D98", high = "#C21F3A", midpoint = 0) +
geom_point(alpha = 1, size = 12, shape = 22) +
theme_classic() +
theme(aspect.ratio = length(gene_set), axis.title = element_blank(),
axis.text.x = element_blank(),
axis.line.x = element_blank(),
axis.ticks.x = element_blank()) +
labs(fill = "log2-FC (treatment/mock)")
print(p_logfc_heat)

pdf(file = "../runs/guess_the_plots/p_logfc_heat.pdf", width = 6, height = 5)
print(p_logfc_heat)
print(p_logfc_heat + theme(legend.position = "none"))
dev.off()
## quartz_off_screen
## 2