Customizing 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.

In [1]:
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)
Out[1]:
Country GDP_2025_Trillion_USD
0 United States 30.34
1 China 19.53
2 Germany 4.92
In [2]:
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))

1. Auto-layout

By default, the first sector is positioned counterclockwise from the start point (12 o’clock), while the remaining sectors are arranged clockwise.

In [3]:
p + geom_pie(size=.6, size_unit='x', stat='identity')
Out[3]:

2. direction

Use 1 for clockwise (default) or -1 for counterclockwise.

In [4]:
p + geom_pie(size=.6, size_unit='x', stat='identity',
             direction=-1)    # <-- counterclockwise
Out[4]:

2. start

Specifies the starting angle of the first slice in degrees.

In [5]:
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')
])
Out[5]: