pegasus.compo_plot

pegasus.compo_plot(data, groupby, condition, style='frequency', restrictions=None, xlabel=None, panel_size=(6, 4), left=0.15, bottom=0.15, wspace=0.3, hspace=0.15, return_fig=False, dpi=300.0, **kwargs)[source]

Generate a composition plot, which shows the percentage of cells from each condition for every cluster.

This function is used to generate composition plots, which are bar plots showing the cell compositions (from different conditions) for each cluster. This type of plots is useful to fast assess library quality and batch effects.

Parameters
  • data (AnnData or UnimodalData or MultimodalData object) – Single cell expression data.

  • groupby (str) – A categorical variable in data.obs that is used to categorize the cells, e.g. cell type.

  • condition (str) – A categorical variable in data.obs that is used to calculate frequency within each category defined by ‘groupby’, e.g. donor.

  • style (str, optional (default: frequency)) – Composition plot style. Can be either frequency, or ‘normalized’. Within each cluster, the frequency style show the percentage of cells from each ‘condition’ within each category in ‘groupby’ (stacked), the normalized style shows for each category in ‘groupby’ the percentage of cells that are also in each ‘condition’ over all cells that are in the same ‘condition’ (not stacked).

  • restrictions (str or List[str], optional, default: None) – A list of restrictions to subset data for plotting. Each restriction takes the format of ‘key:value,value…’, or ‘key:~value,value…’. This restriction selects cells with the data.obs[key] values belong to ‘value,value…’ (or not belong to if ‘~’ shows).

  • xlabel (str, optional (default None)) – Label for the horizontal axis. If None, use ‘groupby’.

  • panel_size (tuple, optional (default: (6, 4))) – The plot size (width, height) in inches.

  • left (float, optional (default: 0.15)) – This parameter sets the figure’s left margin as a fraction of panel’s width (left * panel_size[0]).

  • bottom (float, optional (default: 0.15)) – This parameter sets the figure’s bottom margin as a fraction of panel’s height (bottom * panel_size[1]).

  • wspace (float, optional (default: 0.3)) – This parameter sets the width between panels and also the figure’s right margin as a fraction of panel’s width (wspace * panel_size[0]).

  • hspace (float, optional (defualt: 0.15)) – This parameter sets the height between panels and also the figure’s top margin as a fraction of panel’s height (hspace * panel_size[1]).

  • return_fig (bool, optional, default: False) – Return a Figure object if True; return None otherwise.

  • dpi (float, optional, default: 300.0) – The resolution in dots per inch.

Returns

A matplotlib.figure.Figure object containing the dot plot if return_fig == True

Return type

Figure object

Examples

>>> fig = pg.compo_plot(data, 'louvain_labels', 'Donor', style = 'normalized')