Skip to content

coord_polar

coord_polar(
    xlim: Sequence[Number | None] | None = None,
    ylim: Sequence[Number | None] | None = None,
    theta: Literal["x", "y"] | None = None,
    start: Number | None = None,
    direction: Literal[1, -1] | None = None,
    transform_bkgr: bool | None = None,
) -> FeatureSpec

Bend the panel into a circle, for pie, donut, rose and radar charts.

Parameters:

  • xlim (list, default: None ) –

    As in coord_cartesian.

  • ylim (list, default: None ) –

    As in coord_cartesian.

  • theta ((x, y), default: "x" ) –

    The aesthetic that runs around the circle; the other is the radius.

  • start (float, default: 0 ) –

    Offset from 12 o'clock, in radians.

  • direction ((1, -1), default: 1 ) –

    1 runs clockwise, -1 counter-clockwise.

  • transform_bkgr (bool, default: True ) –

    Draw the panel background and border as a circle, else as a rectangle.

Returns:

  • FeatureSpec –

    The coordinate system.

Notes

HTML output is static: no tooltips, zoom or interactive legend. geom_raster, geom_imshow and side panels cannot be bent and raise SpecError.

Examples:

>>> from ggrust import *
>>> data = {"part": ["a", "b", "c"], "share": [50, 30, 20], "all": ["", "", ""]}
>>> plot = ggplot(data, aes("all", "share", fill="part")) + geom_bar(stat="identity", width=1)
>>> plot = plot + coord_polar(theta="y")

A rose chart: one bar per category around the circle, its value as the radius:

>>> rain = {"month": ["Jan", "Mar", "May", "Jul", "Sep", "Nov"],
...         "mm": [80, 55, 40, 20, 60, 95]}
>>> plot = ggplot(rain, aes("month", "mm", fill="mm")) + geom_bar(stat="identity", width=1)
>>> plot = plot + coord_polar()

The pie again, starting at 6 o'clock and running counter-clockwise:

>>> pie = ggplot(data, aes("all", "share", fill="part")) + geom_bar(stat="identity", width=1)
>>> plot = pie + coord_polar(theta="y", start=3.1416, direction=-1)

A rose chart: one bar per category around the circle, its value as the radius

The pie again, starting at 6 o'clock and running counter-clockwise