Skip to content

Radarplot API

Ilia Popov edited this page May 7, 2025 · 5 revisions

Radarplot FUNCTION

This API provides a function to create a radar plot from KEGGaNOG multi-sample output. It visualizes completeness values of selected pathways across multiple samples in a circular (radial) format.

radarplot(df, pathways, ...)

PARAMETERS

PARAMETER DESCRIPTION
df Input data as a pandas DataFrame
TYPE: pd.DataFrame
pathways List of pathway names to include in the radar plot
TYPE: List[str]
figsize Size of the figure (width, height)
TYPE: Tuple[int, int]
DEFAULT: (8, 8)
colors List of colors for the samples
TYPE: List[str] or None
DEFAULT: None
sample_order Custom order of sample names
TYPE: List[str] or None
DEFAULT: None
title Plot title
TYPE: str or None
DEFAULT: None
title_fontsize Font size of title
TYPE: float
DEFAULT: 14.0
title_color Font color of title
TYPE: str
DEFAULT: "black"
title_weight Font weight of title
TYPE: str
DEFAULT: "normal"
title_style Font style of title
TYPE: str
DEFAULT: "normal"
title_y Vertical alignment of the title
TYPE: float
DEFAULT: 1.1
label_fontsize Font size of axis labels (pathways)
TYPE: float
DEFAULT: 10.0
label_color Font color of axis labels
TYPE: str
DEFAULT: "black"
label_weight Font weight of axis labels
TYPE: str
DEFAULT: "normal"
label_style Font style of axis labels
TYPE: str
DEFAULT: "normal"
label_background Background color of axis labels
TYPE: str or None
DEFAULT: None
label_edgecolor Edge color of axis label boxes
TYPE: str or None
DEFAULT: None
label_pad Padding for labels
TYPE: float
DEFAULT: 1.05
ytick_fontsize Font size of radial axis ticks
TYPE: float
DEFAULT: 8.0
ytick_color Font color of radial axis ticks
TYPE: str
DEFAULT: "black"
ytick_weight Font weight of radial axis ticks
TYPE: str
DEFAULT: "normal"
ytick_alpha Alpha (opacity) of radial ticks
TYPE: float
DEFAULT: 0.5
yticklabels Custom labels for radial axis ticks
TYPE: List[str] or None
DEFAULT: None
fill_alpha Transparency of the filled area
TYPE: float
DEFAULT: 0.2
line_width Line width of radar plot borders
TYPE: float
DEFAULT: 2.0
line_style Line style
TYPE: str
DEFAULT: "-"
legend_loc Legend position keyword
TYPE: str
DEFAULT: "upper right"
legend_bbox Manual legend box anchor
TYPE: Tuple[float, float] or None
DEFAULT: None
show_legend Whether to display legend
TYPE: bool
DEFAULT: True
background_color Background color of the figure
TYPE: str or None
DEFAULT: None

RETURNS

Returns an object with:

  • fig: the Matplotlib figure object
  • ax: the Matplotlib axis object

The object includes .plotfig() and .savefig() methods for convenience.


USAGE EXAMPLE

First, run KEGGaNOG in multi-sample mode:

Where to get demo data? Here

! KEGGaNOG -M -i demo_data/listFile.txt -o KEGGaNOG_multi_output

Then you can build a radar plot of selected pathways across samples:

import kegganog as kgn
import pandas as pd

df = pd.read_csv("KEGGaNOG_multi_output/merged_pathways.tsv", sep="\t")

# List of pathways to visualize
pathways = ["Glycolysis", "Chemotaxis", "Cobalamin biosynthesis"]
# Order of samples on radar plot
sample_order = ["SoCe", "PsePu", "CloAce", "BaSu", "MeRu", "AciSa", "StaCa", "LaPla", "BaThe", "TheMa"]


kgnradar = kgn.radarplot(
    df,
    pathways=pathways,
    sample_order=sample_order,
    label_weight="bold",
    label_background="white",
    label_edgecolor="black",
    label_pad=1.15,
    colors=["#1f77b4", "#2ca02c", "#ff7f0e"],
    yticklabels=["0.2", "", "0.6", "", "1.0"],
    fill_alpha=0.15
)

# Show the figure
kgnradar.plotfig()

Sample output:

image

To save the plot:

kgnradar.savefig("pic_name.png", dpi=600)

Clone this wiki locally