Function that takes a data frame with a Geneid column and several columns for expression data of different samples (e.g. TPMs, Log2FC...) and draws a correlation plot

expressionCor(
  df,
  genes = NULL,
  samples = NULL,
  samples_order = samples,
  corr_method = "pearson",
  plot_type = "lower",
  plot_diagonal = TRUE,
  plot_size = 85,
  plot_border = TRUE,
  plot_colors = c("Gold3", "White", "Cornflowerblue"),
  plot_title = NULL,
  plot_subtitle = NULL,
  plot_caption = NULL,
  cell_border = "Black",
  legend_pos = "right",
  legend_size = c(8, plot_size),
  legend_limits = c(-1, 1),
  legend_breaks_by = 0.5,
  legend_title = paste(stringr::str_to_sentence(corr_method), "correlation", sep = " "),
  legend_title_size = 10,
  coeffs_color = "Black",
  coeffs_size = 4,
  title_hjust = 0.5,
  title_face = "plain",
  title_size = 12,
  subtitle_face = "italic",
  subtitle_size = 11,
  caption_size = 6,
  axis_text_size = 8,
  axis_text_color = "black",
  by_groups = F
)

Arguments

df

Dataframe with a 'Geneid' column and several columns with numerical expression data for different samples, such as TPMs or Log2FC.

genes

Character or NULL. Names of the genes to be used for the correlation analysis. They must present in the column 'Geneid' of 'df'. If NULL, all genes in the data frame are used. Default: NULL

samples

Character or NULL. Names of the samples to be used for the correlation analysis. They must be column names of 'df'. If NULL, all samples are used. Default: NULL.

corr_method

Character of length 1. Correlation method to be passed through cor(). One of "pearson", "spearman" or "kendall". Default: "pearson".

plot_type

Character of length 1. Type of the correlation plot. One of "full", "upper" or "lower". Default: "lower".

plot_diagonal

Logical of length 1. Whether to plot the diagonal or not if the plot type is upper or lower. Default: TRUE.

plot_size

Numerical of length 1. Size in milimeters of the plot. The same number is used for plot height and plot width Default: 85.

plot_border

Logical of length 1. Whether to draw a border in the panel or not. Default: TRUE.

plot_colors

Character of length 3. Colors of the lower, midpoint and higher limits of the scale. Default: c("Gold3", "White", "Cornflowerblue").

plot_title

Character of length 1 or NULL. Title of the plot. Defalut: NULL.

plot_subtitle

Character of length 1 or NULL. Subtitle of the plot. Defalut: NULL.

plot_caption

Character of length 1 or NULL. Caption of the plot. Defalut: NULL.

cell_border

Charachter of length 1, NULL or NA. Color of the cell border. Default: "Black".

legend_pos

Charachter of length 1. Position of the legend, to be passed through ggpubr::theme_pubr(). Default: "right".

legend_size

Numerical of length 2. Size of the legend. The first element is the width and the second is the height of the legend bar. Default: c(8,plot_size)

legend_limits

Numerical of length 2. Lower and upper limits of the correlation scale. Default: c(-1,1).

legend_breaks_by

Numerical of length 1. Size of the breaks in the legend. Default: 0.5.

legend_title

Character of length 1 or NULL. Title of the legend. Default: paste(stringr::str_to_sentence(corr_method), "correlation", sep = " ").

legend_title_size

Numerical of length 1. Size of the legend title. Default: 10.

coeffs_color

Character of length 1 or NULL. Color of the correlation coeficients to be plotted. If NULL, no correlation coefficients are plotted. Default: "Black".

coeffs_size

Numerical of length 1. Size of the correlation coefficients. Default: 4.

title_hjust

Numerical of length 1. Horizontal justification of the title and the subtitle. Default: 0.5.

title_face

Character of length 1. Face of the title text. One of "plain", "italic", "bold". Default: "plain".

title_size

Numerical of length 1. Size of the title text. Default: 12.

subtitle_face

Character of length 1. Face of the subtitle text. One of "plain", "italic", "bold". Default: "italic".

subtitle_size

Numerical of length 1. Size of the subtitle text. Default: 11.

caption_size

Numerical of length 1. Size of the plot caption. Default: 6.

axis_text_size

Numerical of length 1. Size of the text in the axes. Default: 7.

axis_text_color

Character of length 1. Color of the text in the axes. Default: "Black".

by_groups

Logical of length 1. If TRUE, the function searches an extra column named 'group', whose values will be used to separate the plot into facets using facet_wrap(). Default: FALSE.

Author

amitjavilaventura