pegasus.compo_plot

pegasus.compo_plot(data, groupby, condition, style='frequency', restrictions=None, switch_axes=False, groupby_label=None, sort_function='natsorted', panel_size=(6, 4), palette=None, color_unused=False, 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).

  • switch_axes (bool, optional, default: False) – By default, X axis is for groupby, and Y axis for frequencies with respect to condition. If this parameter is True, switch the axes.

  • groupby_label (str, optional (default None)) – Label for the axis displaying groupby categories. If None, use groupby.

  • sort_function (Union[Callable[List[str], List[str]], str], optional, default: natsorted) – Function used for sorting both groupby and condition labels. If natsorted, apply natsorted function to sort by natural order. If None, don’t sort. Otherwise, a callable function will be applied to the labels for sorting.

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

  • palette (List[str], optional (default: None)) – Used for setting colors for categories in condition. Within the list, each string is the color for one category.

  • 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.

Return type

Optional[Figure]

Returns

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

Examples

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