plotProportion: Visualize proportion across two categorical variables

View source: R/visualization.R

plotProportionR Documentation

Visualize proportion across two categorical variables

Description

plotProportionBar creates bar plots comparing the cross-category proportion. plotProportionDot creates dot plots. plotClusterProportions has variable pre-specified and calls the dot plot. plotProportion produces a combination of both bar plots and dot plot.

Having package "ggrepel" installed can help adding tidier percentage annotation on the pie chart. Run options(ggrepel.max.overlaps = n) before plotting to set allowed label overlaps.

Usage

plotProportion(
  object,
  class1 = NULL,
  class2 = "dataset",
  method = c("stack", "group", "pie"),
  ...
)

plotProportionDot(
  object,
  class1 = NULL,
  class2 = "dataset",
  showLegend = FALSE,
  panelBorder = TRUE,
  ...
)

plotProportionBar(
  object,
  class1 = NULL,
  class2 = "dataset",
  method = c("stack", "group"),
  inclRev = FALSE,
  panelBorder = TRUE,
  combinePlot = TRUE,
  ...
)

plotClusterProportions(object, useCluster = NULL, return.plot = FALSE, ...)

plotProportionPie(
  object,
  class1 = NULL,
  class2 = "dataset",
  labelSize = 4,
  labelColor = "black",
  circleColors = NULL,
  ...
)

Arguments

object

A liger object.

class1, class2

Each should be a single name of a categorical variable available in cellMeta slot. Number of cells in each categories in class2 will be served as the denominator when calculating proportions. By default class1 = NULL and uses default clusters and class2 = "dataset".

method

For bar plot, choose whether to draw "stack" or "group" bar plot. Default "stack".

...

Arguments passed on to .ggplotLigerTheme

title,subtitle,xlab,ylab

Main title, subtitle or X/Y axis title text. By default, no main title or subtitle will be set, and X/Y axis title will be the names of variables used for plotting. Use NULL to hide elements. TRUE for xlab or ylab shows default values.

legendFillTitle

Legend title text for fill aesthetics, often used for violin, box, bar plots. Default NULL shows the original variable name.

legendPosition

Text indicating where to place the legend. Choose from "top", "bottom", "left" or "right". Default "right".

baseSize

One-parameter control of all text sizes. Individual text element sizes can be controlled by other size arguments. "Title" sizes are 2 points larger than "text" sizes when being controlled by this.

titleSize,xTitleSize,yTitleSize,legendTitleSize

Size of main title, axis titles and legend title. Default NULL controls by baseSize + 2.

subtitleSize,xTextSize,yTextSize,legendTextSize

Size of subtitle text, axis texts and legend text. Default NULL controls by baseSize.

colorLabels

Character vector for modifying category names in a color legend. Passed to ggplot2::scale_color_manual(labels). Default NULL uses original levels of the factor.

colorValues

Character vector of colors for modifying category colors in a color legend. Passed to ggplot2::scale_color_manual(values). Default NULL uses internal selected palette when <= 26 categories are presented, otherwise ggplot hues.

legendNRow,legendNCol

Integer, when too many categories in one variable, arranges number of rows or columns. Default NULL, automatically split to ceiling(levels(variable)/15) columns.

colorPalette

For continuous coloring, an index or a palette name to select from available options from ggplot scale_brewer or viridis. Default "magma".

colorDirection

Choose 1 or -1. Applied when colorPalette is from Viridis options. Default -1 use darker color for higher value, while 1 reverses this direction.

colorLow,colorMid,colorHigh,colorMidPoint

All four of these must be specified to customize palette with

naColor

The color code for NA values. Default "#DEDEDE". scale_colour_gradient2. Default NULL.

plotly

Whether to use plotly to enable web based interactive browsing for the plot. Requires installation of package "plotly". Default FALSE.

showLegend

Whether to show the legend. Default TRUE.

panelBorder

Whether to show rectangle border of the panel instead of using ggplot classic bottom and left axis lines. Default FALSE.

inclRev

Logical, for barplot, whether to reverse the specification for class1 and class2 and produce two plots. Default FALSE.

combinePlot

Logical, whether to combine the two plots with plot_grid when two plots are created. Default TRUE.

useCluster

For plotClusterProportions. Same as class1 while class2 is hardcoded with "dataset".

return.plot

[Defunct]

labelSize, labelColor

Settings on pie chart percentage label. Default 4 and "white".

circleColors

Character vector of colors. plotProportionPie parameter for setting the colors of circles, i.e. categorical variable controlled by class2. Default NULL uses ggplot default hues.

Value

ggplot or list of ggplot

Examples

plotProportion(pbmcPlot)
plotProportionBar(pbmcPlot, method = "group")
plotProportionPie(pbmcPlot)

rliger documentation built on Oct. 30, 2024, 1:07 a.m.