geom_pie() with start and direction Parameters¶Two new parameters have been added to the geom_pie() function:
start: specifies the starting angle of the first slice in degrees (0-360°)direction: controls sector layout direction (1 for clockwise or -1 for counterclockwise)Previously, pie charts were limited by fixed positioning where the second slice always started at 0° and all slices were arranged clockwise.
These new parameters provide precise control over slice positioning and orientation.
from lets_plot import *
import pandas as pd
LetsPlot.setup_html()
data = pd.read_csv("https://raw.githubusercontent.com/JetBrains/lets-plot/refs/heads/master/docs/f-25a/data/gdp_forecast_2025_trillion_usd.csv", encoding ='utf-8')
data.head(3)
p = ggplot(data, aes(fill='Country', slice='GDP_2025_Trillion_USD')) \
+ ggtitle('GDP forecast 2025 (trillion US$) by country',
subtitle='Source: <a href="https://en.wikipedia.org/wiki/List_of_countries_by_GDP_(nominal)">Wikipedia</a>') \
+ scale_fill_gradient(low="blue", high="yellow") \
+ theme_void() + theme(plot_title=element_text(hjust=0.5), plot_subtitle=element_text(hjust=0.5))
By default, the first sector is positioned counterclockwise from the start point (12 o’clock), while the remaining sectors are arranged clockwise.
p + geom_pie(size=.6, size_unit='x', stat='identity')
direction¶Use 1 for clockwise (default) or -1 for counterclockwise.
p + geom_pie(size=.6, size_unit='x', stat='identity',
direction=-1) # <-- counterclockwise
start¶Specifies the starting angle of the first slice in degrees.
gggrid([
p + geom_pie(size=.9, size_unit='x', stat='identity') + ggtitle('Auto'),
p + geom_pie(size=.9, size_unit='x', start=0, stat='identity') + ggtitle('start=0'),
p + geom_pie(size=.9, size_unit='x', start=180, stat='identity') + ggtitle('start=180')
])