18 Polar Coordinates
For polar coordinates, (pj/coord :polar) maps x to angle and y to radius. Bars become arc-interpolated wedges (rose charts), and scatter points wrap into a disc. Currently best suited for point and bar-family marks; tick labels and axis labels are not yet rendered under :polar.
(ns plotje-book.polar
(:require
;; Rdatasets -- standard datasets
[scicloj.metamorph.ml.rdatasets :as rdatasets]
;; Kindly -- notebook rendering protocol
[scicloj.kindly.v4.kind :as kind]
;; Plotje -- composable plotting
[scicloj.plotje.api :as pj]))(def wind {:direction ["N" "NE" "E" "SE" "S" "SW" "W" "NW"]
:speed [12 8 15 10 7 13 9 11]})Polar Scatter
The same scatter plot, wrapped into polar space. x maps to angle (clockwise from 12 oβclock), y maps to radius (center = minimum, edge = maximum).
(-> (rdatasets/datasets-iris)
(pj/lay-point :sepal-length :sepal-width {:color :species})
(pj/coord :polar))Rose Chart (Coxcomb Diagram)
A bar chart in polar coordinates produces a rose chart β wedge area encodes count. Bars are arc-interpolated for smooth curved edges.
(-> (rdatasets/datasets-iris)
(pj/lay-bar :species)
(pj/coord :polar))Wind Rose
A value-bar chart in polar makes a wind rose β each direction gets a wedge proportional to wind speed.
(-> wind
(pj/lay-value-bar :direction :speed)
(pj/coord :polar))Polar Stacked Bar
Stacked bars in polar show composition within each wedge.
(-> (rdatasets/palmerpenguins-penguins)
(pj/lay-bar :island {:position :stack :color :species})
(pj/coord :polar))Polar Histogram
A histogram in polar wraps bins around the circle. Useful for circular distributions (e.g., time of day, compass bearing).
(-> (rdatasets/datasets-iris)
(pj/lay-histogram :sepal-length)
(pj/coord :polar))Explicit Labels with Polar
By default, polar suppresses auto-generated axis labels (since there are no rectangular axes). You can still set a title with pj/options:
(-> (rdatasets/datasets-iris)
(pj/lay-point :sepal-length :sepal-width {:color :species})
(pj/coord :polar)
(pj/options {:title "Iris in Polar Space"}))Whatβs Next
- Cookbook β recipes for common multi-layer plots
- Customization β colors, annotations, and interactive features
source: notebooks/plotje_book/polar.clj