do_MetadataPlot: Compute a heatmap of categorical variables.

View source: R/do_MetadataPlot.R

do_MetadataPlotR Documentation

Compute a heatmap of categorical variables.

Description

The main use of this function is to generate a metadata heatmap of your categorical data, normally targeted to the different patient samples one has in the Seurat object. It requires that the metadata columns chosen have one and only one possible value for each of the values in group.by.

Usage

do_MetadataPlot(
  sample = NULL,
  group.by = NULL,
  metadata = NULL,
  from_df = FALSE,
  df = NULL,
  colors.use = NULL,
  cluster = TRUE,
  flip = TRUE,
  heatmap.gap = 1,
  axis.text.x.angle = 45,
  legend.position = "bottom",
  font.size = 14,
  legend.font.size = NULL,
  legend.symbol.size = NULL,
  legend.ncol = NULL,
  legend.nrow = NULL,
  legend.byrow = FALSE,
  na.value = "grey75",
  font.type = "sans",
  grid.color = "white",
  border.color = "black",
  plot.title.face = "bold",
  plot.subtitle.face = "plain",
  plot.caption.face = "italic",
  axis.title.face = "bold",
  axis.text.face = "plain",
  legend.title.face = "bold",
  legend.text.face = "plain",
  xlab = "",
  ylab = ""
)

Arguments

sample

Seurat | A Seurat object, generated by CreateSeuratObject.

group.by

character | Metadata column to use as basis for the plot.

metadata

character | Metadata columns that will be used to plot the heatmap on the basis of the variable provided to group.by.

from_df

logical | Whether to provide a data frame with the metadata instead.

df

data.frame | Data frame containing the metadata to plot. Rows contain the unique values common to all columns (metadata variables). The columns must be named.

colors.use

named_list | A named list of named vectors. The names of the list correspond to the names of the values provided to metadata and the names of the items in the named vectors correspond to the unique values of that specific metadata variable. The values are the desired colors in HEX code for the values to plot. The used are pre-defined by the pacakge but, in order to get the most out of the plot, please provide your custom set of colors for each metadata column!

cluster

logical | Whether to perform clustering of rows and columns.

flip

logical | Whether to invert the axis of the displayed plot.

heatmap.gap

numeric | Size of the gap between heatmaps in mm.

axis.text.x.angle

numeric | Degree to rotate the X labels. One of: 0, 45, 90.

legend.position

character | Position of the legend in the plot. One of:

  • top: Top of the figure.

  • bottom: Bottom of the figure.

  • left: Left of the figure.

  • right: Right of the figure.

  • none: No legend is displayed.

font.size

numeric | Overall font size of the plot. All plot elements will have a size relationship with this font size.

legend.font.size

numeric | Size of the font size of the legend. NULL uses default theme font size for legend according to the strongfont.size parameter.

legend.symbol.size

numeric | Size of symbols in the legend in mm. NULL uses the default size.

legend.ncol

numeric | Number of columns in the legend.

legend.nrow

numeric | Number of rows in the legend.

legend.byrow

logical | Whether the legend is filled by row or not.

na.value

character | Color value for NA.

font.type

character | Base font family for the plot. One of:

  • mono: Mono spaced font.

  • serif: Serif font family.

  • sans: Default font family.

grid.color

character | Color of the grid in the plot. In heatmaps, color of the border of the cells.

border.color

character | Color for the border of the heatmap body.

plot.title.face, plot.subtitle.face, plot.caption.face, axis.title.face, axis.text.face, legend.title.face, legend.text.face

character | Controls the style of the font for the corresponding theme element. One of:

  • plain: For normal text.

  • italic: For text in itallic.

  • bold: For text in bold.

  • bold.italic: For text both in itallic and bold.

xlab, ylab

character | Titles for the X and Y axis.

Value

A ggplot2 object.

Examples


  # Check Suggests.
  value <- SCpubr:::check_suggests(function_name = "do_MetadataPlot", passive = TRUE)
  
  if (isTRUE(value)){
    # Consult the full documentation in https://enblacar.github.io/SCpubr-book/
    
    # Can also use a Seurat object.
    df <- data.frame(row.names = letters[1:5],
                     "A" = as.character(seq(1, 5)),
                     "B" = rev(as.character(seq(1, 5))))
    
    p <- SCpubr::do_MetadataPlot(from_df = TRUE,
                                 df = df)
    
    p
    
  } else if (base::isFALSE(value)){
    message("This function can not be used without its suggested packages.")
    message("Check out which ones are needed using `SCpubr::state_dependencies()`.")
  }


enblacar/SCpubr documentation built on Aug. 25, 2024, 9:45 p.m.