%useLatestDescriptors
%use dataframe
%use lets-plot
geomPie()
with start
and direction
Parameters¶Two new parameters have been added to the geomPie()
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.
val gdp = DataFrame.readCSV("https://raw.githubusercontent.com/JetBrains/lets-plot/refs/heads/master/docs/f-25a/data/gdp_forecast_2025_trillion_usd.csv")
gdp.head(3)
DataFrame: rowsCount = 3, columnsCount = 2
Country | GDP_2025_Trillion_USD |
---|---|
United States | 30.340000 |
China | 19.530000 |
Germany | 4.920000 |
val p = letsPlot(gdp.toMap()) {
fill="Country"
} +
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>"""
) +
scaleFillGradient(low="blue", high="yellow") +
themeVoid() +
theme(plotTitle=elementText(hjust=0.5), plotSubtitle=elementText(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 + geomPie(size=.6, sizeUnit="x", stat=Stat.identity) {
slice="GDP_2025_Trillion_USD"
}
direction
¶Use 1
for clockwise (default) or -1
for counterclockwise.
p + geomPie(size=.6, sizeUnit="x", stat=Stat.identity,
direction=-1) { // <-- counterclockwise
slice="GDP_2025_Trillion_USD"
}
start
¶Specifies the starting angle of the first slice in degrees.
gggrid(listOf(
p + geomPie(size=.6, sizeUnit="x", stat=Stat.identity) { slice="GDP_2025_Trillion_USD" } + ggtitle("Auto"),
p + geomPie(size=.6, sizeUnit="x", stat=Stat.identity, start=0) { slice="GDP_2025_Trillion_USD" } + ggtitle("start=0"),
p + geomPie(size=.6, sizeUnit="x", stat=Stat.identity, start=180) { slice="GDP_2025_Trillion_USD" } + ggtitle("start=180")
))