Customizing geom_pie()

Two new parameters have been added to the geom_pie() function:

  • direction: Controls the sector layout, allowing it to be drawn either clockwise or counterclockwise.
  • start: Specifies the starting angle of the pie chart in degrees.
In [1]:
from lets_plot import *
LetsPlot.setup_html()

data = {
    'name':  ['a', 'b', 'c', 'd', 'b'], 
    'value': [ 40,  90,  10 , 50,  20]}
p = ggplot(data, aes(fill='name', weight='value')) 

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

In [2]:
p + geom_pie(size=.6, size_unit='x') + ggtitle('geom_pie()')
Out[2]:

direction

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

In [3]:
p + geom_pie(size=.6, size_unit='x', direction=-1) + ggtitle('geom_pie(direction=-1)')
Out[3]:

start

Defines the initial angle in degrees. Setting start = 0 disables the default layout.

In [4]:
dump_plot(gggrid([
    p + geom_pie(size=.9, size_unit='x') + ggtitle('Default'),
    p + geom_pie(size=.9, size_unit='x', start=0) + ggtitle('start=0'),
    p + geom_pie(size=.9, size_unit='x', start=180) + ggtitle('start=180'),
    p + geom_livemap() + geom_pie() + ggtitle('Default'),
    p + geom_livemap() + geom_pie(start=0) + ggtitle('start=0'),
    p + geom_livemap() + geom_pie(start=180) + ggtitle('start=180')
], ncol=3))
Out[4]:
In [5]:
gggrid([
    p + geom_livemap() + geom_pie() + ggtitle('Default'),
    p + geom_livemap() + geom_pie(start=0) + ggtitle('start=0'),
    p + geom_livemap() + geom_pie(start=180) + ggtitle('start=180')
])
Out[5]:
In [ ]: