Skip to contents

Visualizes data using various plot types such as bar plots, rose plots, ring plots, pie charts, trend plots, area plots, dot plots, sankey plots, chord plots, venn diagrams, and upset plots.

Usage

StatPlot(
  meta.data,
  stat.by,
  group.by = NULL,
  split.by = NULL,
  bg.by = NULL,
  flip = FALSE,
  NA_color = "grey",
  NA_stat = TRUE,
  keep_empty = FALSE,
  individual = FALSE,
  stat_level = NULL,
  plot_type = c("bar", "rose", "ring", "pie", "trend", "area", "dot", "sankey", "chord",
    "venn", "upset"),
  stat_type = c("percent", "count"),
  position = c("stack", "dodge"),
  palette = "Paired",
  palcolor = NULL,
  alpha = 1,
  bg_palette = "Paired",
  bg_palcolor = NULL,
  bg_alpha = 0.2,
  label = FALSE,
  label.size = 3.5,
  label.fg = "black",
  label.bg = "white",
  label.bg.r = 0.1,
  aspect.ratio = NULL,
  title = NULL,
  subtitle = NULL,
  xlab = NULL,
  ylab = NULL,
  legend.position = "right",
  legend.direction = "vertical",
  theme_use = "theme_scop",
  theme_args = list(),
  combine = TRUE,
  nrow = NULL,
  ncol = NULL,
  byrow = TRUE,
  force = FALSE,
  seed = 11
)

Arguments

meta.data

The data frame containing the data to be plotted.

stat.by

The column name(s) in meta.data specifying the variable(s) to be plotted.

group.by

The column name in meta.data specifying the grouping variable.

split.by

The column name in meta.data specifying the splitting variable.

bg.by

The column name in meta.data specifying the background variable for bar plots.

flip

Logical indicating whether to flip the plot.

NA_color

The color to use for missing values.

NA_stat

Logical indicating whether to include missing values in the plot.

keep_empty

Logical indicating whether to keep empty groups in the plot.

individual

Logical indicating whether to plot individual groups separately.

stat_level

The level(s) of the variable(s) specified in stat.by to include in the plot.

plot_type

The type of plot to create. Can be one of "bar", "rose", "ring", "pie", "trend", "area", "dot", "sankey", "chord", "venn", or "upset".

stat_type

The type of statistic to compute for the plot. Can be one of "percent" or "count".

position

The position adjustment for the plot. Can be one of "stack" or "dodge".

palette

The name of the color palette to use for the plot.

palcolor

The color to use in the color palette.

alpha

The transparency level for the plot.

bg_palette

The name of the background color palette to use for bar plots.

bg_palcolor

The color to use in the background color palette.

bg_alpha

The transparency level for the background color in bar plots.

label

Logical indicating whether to add labels on the plot.

label.size

The size of the labels.

label.fg

The foreground color of the labels.

label.bg

The background color of the labels.

label.bg.r

The radius of the rounded corners of the label background.

aspect.ratio

The aspect ratio of the plot.

title

The main title of the plot.

subtitle

The subtitle of the plot.

xlab

The x-axis label of the plot.

ylab

The y-axis label of the plot.

legend.position

The position of the legend in the plot. Can be one of "right", "left", "bottom", "top", or "none".

legend.direction

The direction of the legend in the plot. Can be one of "vertical" or "horizontal".

theme_use

The name of the theme to use for the plot. Can be one of the predefined themes or a custom theme.

theme_args

A list of arguments to be passed to the theme function.

combine

Logical indicating whether to combine multiple plots into a single plot.

nrow

The number of rows in the combined plot.

ncol

The number of columns in the combined plot.

byrow

Logical indicating whether to fill the plot by row or by column.

force

Logical indicating whether to force the plot even if some variables have more than 100 levels.

seed

The random seed to use for reproducible results.

See also

Examples

data("pancreas_sub")
head(pancreas_sub@meta.data)
#>                     orig.ident nCount_RNA nFeature_RNA    S_score   G2M_score
#> AAACCTGGTATTAGCC SeuratProject       8610         2980  0.3850226 -0.21053730
#> AAACCTGTCTTTCCTC SeuratProject       9592         3410  0.5562343 -0.05274934
#> AAACGGGAGTCAATAG SeuratProject       9720         3121  0.6643318  0.27641058
#> AAACGGGCACTGTGTA SeuratProject       7173         2664  0.1745044 -0.16067627
#> AAACGGGCAGTTCCCT SeuratProject       6342         2430 -0.1568091 -0.16858186
#> AAACGGGGTCGGGTCT SeuratProject       5818         2343 -0.2308148 -0.26084459
#>                  nCount_spliced nFeature_spliced nCount_unspliced
#> AAACCTGGTATTAGCC           8610             2980             1097
#> AAACCTGTCTTTCCTC           9592             3410             1335
#> AAACGGGAGTCAATAG           9720             3121             1127
#> AAACGGGCACTGTGTA           7173             2664              830
#> AAACGGGCAGTTCCCT           6342             2430             1111
#> AAACGGGGTCGGGTCT           5818             2343             1566
#>                  nFeature_unspliced  CellType SubCellType Phase
#> AAACCTGGTATTAGCC                747    Ductal      Ductal     S
#> AAACCTGTCTTTCCTC                892    Ductal      Ductal     S
#> AAACGGGAGTCAATAG                769    Ductal      Ductal     S
#> AAACGGGCACTGTGTA                591    Ductal      Ductal     S
#> AAACGGGCAGTTCCCT                806    Ductal      Ductal    G1
#> AAACGGGGTCGGGTCT               1055 Endocrine       Alpha    G1
StatPlot(
  pancreas_sub@meta.data,
  stat.by = "Phase",
  group.by = "CellType",
  plot_type = "bar",
  label = TRUE
)


StatPlot(
  pancreas_sub[["RNA"]]@meta.data,
  stat.by = "highly_variable_genes",
  plot_type = "ring",
  label = TRUE
)
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_col()`).
#> Warning: Removed 1 row containing missing values or values outside the scale range
#> (`geom_text_repel()`).


pancreas_sub <- AnnotateFeatures(
  pancreas_sub,
  species = "Mus_musculus",
  IDtype = "symbol",
  db = c("VerSeDa", "TF")
)
#>  [2025-07-03 08:51:16] Species: Mus_musculus
#>  [2025-07-03 08:51:16] Preparing database: TF
#> ! [2025-07-03 08:51:20] Error in utils::download.file(url = url, destfile = destfile, method = method, : cannot open URL 'http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Mus_musculus_TF'
#> ! [2025-07-03 08:51:20] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Mus_musculus_TF
#> ! [2025-07-03 08:51:20] Failed to download using "auto". Retry...
#> ! [2025-07-03 08:51:23] Error in utils::download.file(url = url, destfile = destfile, method = method, : 'wget' call had nonzero exit status
#> ! [2025-07-03 08:51:23] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Mus_musculus_TF
#> ! [2025-07-03 08:51:23] Failed to download using "wget". Retry...
#> ! [2025-07-03 08:51:27] Error in utils::download.file(url = url, destfile = destfile, method = method, : cannot open URL 'http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Mus_musculus_TF'
#> ! [2025-07-03 08:51:27] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Mus_musculus_TF
#> ! [2025-07-03 08:51:27] Failed to download using "libcurl". Retry...
#> ! [2025-07-03 08:51:32] Error in utils::download.file(url = url, destfile = destfile, method = method, : cannot open URL 'http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Mus_musculus_Cof'
#> ! [2025-07-03 08:51:32] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Mus_musculus_Cof
#> ! [2025-07-03 08:51:32] Failed to download using "auto". Retry...
#> ! [2025-07-03 08:51:34] Error in utils::download.file(url = url, destfile = destfile, method = method, : 'wget' call had nonzero exit status
#> ! [2025-07-03 08:51:34] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Mus_musculus_Cof
#> ! [2025-07-03 08:51:34] Failed to download using "wget". Retry...
#> ! [2025-07-03 08:51:38] Error in utils::download.file(url = url, destfile = destfile, method = method, : cannot open URL 'http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Mus_musculus_Cof'
#> ! [2025-07-03 08:51:38] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Mus_musculus_Cof
#> ! [2025-07-03 08:51:38] Failed to download using "libcurl". Retry...
#> ! [2025-07-03 08:51:41] Use the human annotation to create the TF database for Mus_musculus
#> ! [2025-07-03 08:51:43] Error in utils::download.file(url = url, destfile = destfile, method = method, : cannot open URL 'http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Homo_sapiens_TF'
#> ! [2025-07-03 08:51:43] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Homo_sapiens_TF
#> ! [2025-07-03 08:51:43] Failed to download using "auto". Retry...
#> ! [2025-07-03 08:51:47] Error in utils::download.file(url = url, destfile = destfile, method = method, : 'wget' call had nonzero exit status
#> ! [2025-07-03 08:51:47] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Homo_sapiens_TF
#> ! [2025-07-03 08:51:47] Failed to download using "wget". Retry...
#> ! [2025-07-03 08:51:49] Error in utils::download.file(url = url, destfile = destfile, method = method, : cannot open URL 'http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Homo_sapiens_TF'
#> ! [2025-07-03 08:51:49] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/TF_list_final/Homo_sapiens_TF
#> ! [2025-07-03 08:51:49] Failed to download using "libcurl". Retry...
#> ! [2025-07-03 08:51:55] Error in utils::download.file(url = url, destfile = destfile, method = method, : cannot open URL 'http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Homo_sapiens_Cof'
#> ! [2025-07-03 08:51:55] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Homo_sapiens_Cof
#> ! [2025-07-03 08:51:55] Failed to download using "auto". Retry...
#> ! [2025-07-03 08:51:58] Error in utils::download.file(url = url, destfile = destfile, method = method, : 'wget' call had nonzero exit status
#> ! [2025-07-03 08:51:58] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Homo_sapiens_Cof
#> ! [2025-07-03 08:51:58] Failed to download using "wget". Retry...
#> ! [2025-07-03 08:52:01] Error in utils::download.file(url = url, destfile = destfile, method = method, : cannot open URL 'http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Homo_sapiens_Cof'
#> ! [2025-07-03 08:52:01] Cannot download from the url: http://bioinfo.life.hust.edu.cn/AnimalTFDB4/static/download/Cof_list_final/Homo_sapiens_Cof
#> ! [2025-07-03 08:52:01] Failed to download using "libcurl". Retry...
#> Error in data.frame(Term = "TF", symbol = tf[["Symbol"]]): arguments imply differing number of rows: 1, 0
StatPlot(
  GetFeaturesData(pancreas_sub, "RNA"),
  stat.by = "TF",
  group.by = "VerSeDa",
  stat_type = "count",
  plot_type = "bar",
  position = "dodge",
  label = TRUE,
  NA_stat = FALSE
)
#> Error: VerSeDa is not in the meta.data.