jj_plot_fc_fc: show results from differential expression analysis

View source: R/jj_plot_fc_fc.R

jj_plot_fc_fcR Documentation

show results from differential expression analysis

Description

jj_plot_fc_fc plot fold changes from two different DEG analyses against each other

Usage

jj_plot_fc_fc(
  plot_df,
  logfc_column1,
  logfc_column2,
  symbol_column = NULL,
  labs_range = c(-2, 2, -2, 2),
  marker_thres = 0.5,
  col_vec = c("red", "blue", "black", "green"),
  alpha = 1,
  pt.size = 1,
  highlight.pt.size = 1,
  only_highlight = FALSE,
  markers_highlight = NULL,
  col_by_highlight = FALSE,
  use_text = FALSE,
  add_thres_line = FALSE,
  markers_highlight_col = NULL
)

Arguments

symbol_column

provide symbol_column to add text to all points that are highlighted (when use_text=TRUE)

labs_range

vector specifying range of x axis (and for fc_fc plot range of y axis)

marker_thres

define marker_thres to highlight all points with absolute value above

col_vec

define larger, smaller, intermediate and highlight colours

alpha

alpha level for points (working?)

only_highlight

if TRUE, only show markers specified in markers_highlight

markers_highlight

vector of genes from the symbol_column which should additionally be highlighted

col_by_highlight

if TRUE, only colour the markers specified in markers_highlight

use_text

plot text if there are any points to highlight

add_thres_line

if TRUE, plot dashed lines at the defined marker_thres

markers_highlight_col

named vector assigning a colour to each gene to be highlighed

logfc_column

sparse matrix, vector, or data.frame

pval_column

vector with group annotation, has to have length equal to ncol(sparse_mat)/nrow(data.frame)/length(vector)

Value

ggplot scatterplot of log10(pval) vs FC or FC vs FC

Examples

#Using Seurats FindMarkers()
library(Seurat)
marker_df = FindMarkers(pbmc_small, group.by = 'groups', ident.1 = 'g1', ident.2 = 'g2')
marker_df$symbol = rownames(marker_df)
marker_df2 = FindMarkers(pbmc_small, group.by = 'RNA_snn_res.1', ident.1 = '0', ident.2 = '1')
marker_df2$symbol = rownames(marker_df2)
markers_joined = dplyr::inner_join(marker_df, marker_df2, by = 'symbol')
#or using a random data.frame
markers_joined = data.frame(avg_log2FC.x = rnorm(100, 0, 2), avg_log2FC.y = rnorm(100, 0, 2), symbol = paste0(sample(LETTERS, 100, replace = T), sample(letters, 100, replace = T), 1:100))
# simple logFC-logFC plot with highlighting above |avg_log2FC| = 1
jj_plot_fc_fc(plot_df = markers_joined, logfc_column1 = 'avg_log2FC.x', logfc_column2 = 'avg_log2FC.y', marker_thres = 1)    
# adding range to plot and text to markers, also adding threshold lines
jj_plot_fc_fc(markers_joined, logfc_column1 = 'avg_log2FC.x', logfc_column2 = 'avg_log2FC.y',symbol_column = 'symbol', labs_range = c(-4,4, -4,4), marker_thres = 2, use_text = T, add_thres_line = T) 
#specifying custom highlight
jj_plot_fc_fc(markers_joined, logfc_column1 = 'avg_log2FC.x', logfc_column2 = 'avg_log2FC.y',symbol_column = 'symbol', labs_range = c(-4,4, -4,4), marker_thres = 2, use_text = T,  markers_highlight = markers_joined$symbol[1:4], col_by_highlight = T) 
#changing colour and size of custom highlight
jj_plot_fc_fc(markers_joined, logfc_column1 = 'avg_log2FC.x', logfc_column2 = 'avg_log2FC.y',symbol_column = 'symbol',
             labs_range = c(-4,4, -4,4), marker_thres = Inf, use_text = T, markers_highlight = markers_joined$symbol[1:4], 
             col_by_highlight = T,highlight.pt.size = 3, markers_highlight_col = structure(rep('orange',4), names=markers_joined$symbol[1:4])) + guides(colour = 'none')

mathosi/jj documentation built on Feb. 25, 2024, 2:29 p.m.