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, xticklabels_rotation=90.0, yticklabels_rotation=0.0, 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 (
AnnDataorUnimodalDataorMultimodalDataobject) – 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 bygroupby, e.g. donor.style (
str, optional (default:frequency)) – Composition plot style. Can be eitherfrequency, ornormalized. Within each cluster, thefrequencystyle show the percentage of cells from eachconditionwithin each category ingroupby(stacked), thenormalizedstyle shows for each category ingroupbythe percentage of cells that are also in eachconditionover all cells that are in the samecondition(not stacked).restrictions (
strorList[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 thedata.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 isTrue, switch the axes.groupby_label (
str, optional (defaultNone)) – Label for the axis displayinggroupbycategories. IfNone, usegroupby.sort_function (
Union[Callable[List[str], List[str]], str], optional, default:natsorted) – Function used for sorting both groupby and condition labels. Ifnatsorted, apply natsorted function to sort by natural order. IfNone, 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 incondition. 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]).xticklabels_rotation (Optional[float] = 90.0,) – Rotation of x-axis tick labels.
yticklabels_rotation (Optional[float] = 0.0,) – Rotation of y-axis tick labels.
return_fig (
bool, optional, default:False) – Return aFigureobject ifTrue; returnNoneotherwise.dpi (
float, optional, default:300.0) – The resolution in dots per inch.
- Return type
Optional[Figure]- Returns
Figureobject – Amatplotlib.figure.Figureobject containing the dot plot ifreturn_fig == True
Examples
>>> fig = pg.compo_plot(data, 'louvain_labels', 'Donor', style = 'normalized')