Clustered DotPlots using ComplexHeatmap

Clustered_DotPlot(
  seurat_object,
  features,
  split.by = NULL,
  colors_use_exp = viridis_plasma_dark_high,
  exp_color_min = -2,
  exp_color_middle = NULL,
  exp_color_max = 2,
  exp_value_type = "scaled",
  print_exp_quantiles = FALSE,
  colors_use_idents = NULL,
  x_lab_rotate = TRUE,
  plot_padding = NULL,
  flip = FALSE,
  k = 1,
  feature_km_repeats = 1000,
  ident_km_repeats = 1000,
  row_label_size = 8,
  row_label_fontface = "plain",
  grid_color = NULL,
  cluster_feature = TRUE,
  cluster_ident = TRUE,
  column_label_size = 8,
  legend_label_size = 10,
  legend_title_size = 10,
  raster = FALSE,
  plot_km_elbow = TRUE,
  elbow_kmax = NULL,
  assay = NULL,
  group.by = NULL,
  idents = NULL,
  show_parent_dend_line = TRUE,
  ggplot_default_colors = FALSE,
  color_seed = 123,
  seed = 123
)

Arguments

seurat_object

Seurat object name.

features

Features to plot.

split.by

Variable in @meta.data to split the identities plotted by.

colors_use_exp

Color palette to use for plotting expression scale. Default is viridis::plasma(n = 20, direction = -1).

exp_color_min

Minimum scaled average expression threshold (everything smaller will be set to this). Default is -2.

exp_color_middle

What scaled expression value to use for the middle of the provided colors_use_exp. By default will be set to value in middle of exp_color_min and exp_color_max.

exp_color_max

Minimum scaled average expression threshold (everything smaller will be set to this). Default is 2.

exp_value_type

Whether to plot average normalized expression or scaled average normalized expression. Only valid when split.by is provided.

print_exp_quantiles

Whether to print the quantiles of expression data in addition to plots. Default is FALSE. NOTE: These values will be altered by choices of exp_color_min and exp_color_min if there are values below or above those cutoffs, respectively.

colors_use_idents

specify color palette to used for identity labels. By default if number of levels plotted is less than or equal to 36 it will use "polychrome" and if greater than 36 will use "varibow" with shuffle = TRUE both from DiscretePalette_scCustomize.

x_lab_rotate

How to rotate column labels. By default set to TRUE which rotates labels 45 degrees. If set FALSE rotation is set to 0 degrees. Users can also supply custom angle for text rotation.

plot_padding

if plot needs extra white space padding so no plot or labels are cutoff. The parameter accepts TRUE or numeric vector of length 4. If TRUE padding will be set to c(2, 10, 0 0) (bottom, left, top, right). Can also be customized further with numeric vector of length 4 specifying the amount of padding in millimeters. Default is NULL, no padding.

flip

logical, whether to flip the axes of final plot. Default is FALSE; rows = features and columns = idents.

k

Value to use for k-means clustering on features Sets (km) parameter in ComplexHeatmap::Heatmap(). From ComplexHeatmap::Heatmap(): Apply k-means clustering on rows. If the value is larger than 1, the heatmap will be split by rows according to the k-means clustering. For each row slice, hierarchical clustering is still applied with parameters above.

feature_km_repeats

Number of k-means runs to get a consensus k-means clustering for features. Note if feature_km_repeats is set to value greater than one, the final number of groups might be smaller than row_km, but this might mean the original row_km is not a good choice. Default is 1000.

ident_km_repeats

Number of k-means runs to get a consensus k-means clustering. Similar to feature_km_repeats. Default is 1000.

row_label_size

Size of the feature labels. Provided to row_names_gp in Heatmap call.

row_label_fontface

Fontface to use for row labels. Provided to row_names_gp in Heatmap call.

grid_color

color to use for heatmap grid. Default is NULL which "removes" grid by using NA color.

cluster_feature

logical, whether to cluster and reorder feature axis. Default is TRUE.

cluster_ident

logical, whether to cluster and reorder identity axis. Default is TRUE.

column_label_size

Size of the feature labels. Provided to column_names_gp in Heatmap call.

legend_label_size

Size of the legend text labels. Provided to labels_gp in Heatmap legend call.

legend_title_size

Sise of the legend title text labels. Provided to title_gp in Heatmap legend call.

raster

Logical, whether to render in raster format (faster plotting, smaller files). Default is FALSE.

plot_km_elbow

Logical, whether or not to return the Sum Squared Error Elbow Plot for k-means clustering. Estimating elbow of this plot is one way to determine "optimal" value for k. Based on: https://stackoverflow.com/a/15376462/15568251.

elbow_kmax

The maximum value of k to use for plot_km_elbow. Suggest setting larger value so the true shape of plot can be observed. Value must be 1 less than number of features provided. If NULL parameter will be set dependent on length of feature list up to elbow_kmax = 20.

assay

Name of assay to use, defaults to the active assay.

group.by

Group (color) cells in different ways (for example, orig.ident).

idents

Which classes to include in the plot (default is all).

show_parent_dend_line

Logical, Sets parameter of same name in ComplexHeatmap::Heatmap(). From ComplexHeatmap::Heatmap(): When heatmap is split, whether to add a dashed line to mark parent dendrogram and children dendrograms. Default is TRUE.

ggplot_default_colors

logical. If colors_use = NULL, Whether or not to return plot using default ggplot2 "hue" palette instead of default "polychrome" or "varibow" palettes.

color_seed

random seed for the "varibow" palette shuffle if colors_use = NULL and number of groups plotted is greater than 36. Default = 123.

seed

Sets seed for reproducible plotting (ComplexHeatmap plot).

Value

A ComplexHeatmap or if plot_km_elbow = TRUE a list containing ggplot2 object and ComplexHeatmap.

Author

Ming Tang (Original Code), Sam Marsh (Wrap single function, added/modified functionality)

Examples

# \donttest{
library(Seurat)
Clustered_DotPlot(seurat_object = pbmc_small, features = c("CD3E", "CD8", "GZMB", "MS4A1"))
#> Warning: The following features were omitted as they were not found:
#>  CD8
#> Warning: Scaling data with a low number of groups may produce misleading results

#> [[1]]

#> 
#> [[2]]

#> 
# }