knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE, error = FALSE, 
                      fig.width = 6, fig.height = 5, fig.align = "center")

Load packages

library(tidyverse) 
library(ggpubr)
library(patchwork)

library(plotmics)

Run expressionCor()

Required input

The input for expressionCor() is a data frame with a Geneid column and several columns with expression values of each sample. It is required that the values in the Geneid column are unique.

expr <- read.delim("../testdata/tpm.tsv")
expr[1:5,1:5]

Minimum run

expressionCor(df = expr)

Groups and facets

expressionCor() allows to use groups, which then will be used to separate the correlation plots into facets. To enable this, set the parameter by_groups to TRUE. This option requires an extra column named group in which each row will have a determined value.

expr2 <- expr %>% dplyr::mutate(group = c(rep(c("group1", "group2", "group3"), nrow(expr)/3), "group1", "group2"))
head(expr2)
expressionCor(df = expr2, samples = colnames(expr2)[-1], by_groups = T)

Options

In expressionCor(), the default is to compute the Pearson correlation. Nevertheless, the correlation method can be changed to Spearman or Kendall correlations by changing the corr_method argument to "spearman" or "kendall".

expressionCor(df = expr, corr_method = "pearson") + labs(title = "Pearson correlation (default)") +
expressionCor(df = expr, corr_method = "spearman") + labs(title = "Spearman correlation")

Also, the genes and/or samples used to compute the correlation values can be subset using the genes and samples parameters.

expressionCor(df = expr, genes = c("WASH7P", "FAM138A", "AL627309.1")) + labs(title = "Subset of genes") +
expressionCor(df = expr, samples = c("cond3_rep2", "cond1_rep1", "cond2_rep1")) + labs(title = "Subset of samples")

Customization

Heatmap

expressionCor() allows an easy customization of the heatmap:

expressionCor(df = expr, plot_type = "lower") + labs(title = "Lower plot (default)") +
expressionCor(df = expr, plot_type = "upper") + labs(title = "Upper plot") +
expressionCor(df = expr, plot_type = "full") + labs(title = "Full plot")
expressionCor(df = expr, plot_diagonal = F)
expressionCor(df = expr, coeffs_color = "Black") +
expressionCor(df = expr, coeffs_color = "Red", coeffs_size = 6)
expressionCor(expr, plot_colors = c("blue", "yellow", "red"))
expressionCor(df = expr, plot_size = 50)
expressionCor(df = expr, plot_title = "Title", plot_subtitle = "Subtitle", plot_caption = "Caption")
expressionCor(df = expr,axis_text_color = "blue", axis_text_size = 7)
expressionCor(df = expr) +
expressionCor(df = expr, cell_border = "Red") +
expressionCor(df = expr, cell_border = "NA")

Legend

expressionCor() allows an easy customization of the legend:

expressionCor(df = expr, legend_limits = c(0.9,1), legend_breaks_by = 0.05)
expressionCor(df = expr, legend_title  = "Title of the legend")
(expressionCor(df = expr, legend_pos = "left", legend_title = "Legend at the left") +
expressionCor(df = expr, legend_pos = "right", legend_title = "Legend at the right")) /
(expressionCor(df = expr, legend_pos = "top", legend_title = "Legend at the top") +
expressionCor(df = expr, legend_pos = "bottom", legend_title = "Legend at the bottom"))
expressionCor(df = expr, legend_size = c(5,50)) +
expressionCor(df = expr, legend_pos = "bottom", legend_size = c(5,50))


amitjavilaventura/seqViewR documentation built on Nov. 21, 2023, 10:12 a.m.