Help with ggrepel on a polar pie chart: "Viewport has zero dimension(s)" error

Hi everyone,

I’m trying to plot a pie chart using coord_polar() in ggplot2, but I keep getting the same error when I try to add labels with ggrepel::geom_text_repel().

Here’s the code I’m using:

r
ggplot(dados_pizza, aes(ymax = ymax, ymin = ymin, xmax = 1, xmin = 0, fill = discriminacao)) +
geom_rect(color = "grey20") +
coord_polar(theta = "y") +
labs(
title = paste("Receitas Municipais", " - ", ano_escolhido),
fill = "Conta"
) +
scale_fill_manual(
values = paleta_gradual(n_distinct(dados_pizza$discriminacao)),
labels = vetor_legenda_uniao
) +
geom_text(
data = subset(dados_pizza, prop >= 0.05),
aes(x = 0.5, y = ymid, label = prop_label),
inherit.aes = FALSE,
color = "white", size = 3
) +

Error happens here:

ggrepel::geom_text_repel(
data = subset(dados_pizza, 0.01 < prop & prop < 0.05),
aes(x = 1, y = ymid * 0.5, label = prop_label),
inherit.aes = FALSE,
size = 3,
color = "black",
nudge_x = 0.5,
box.padding = 0.2,
point.padding = 0.2,
max.overlaps = 5
) +
theme_void()
The error I get is:

text
Error in grid.Call(C_convert, x, as.integer(whatfrom), as.integer(whatto), :
Viewport has zero dimension(s)
I’ve searched for solutions and even asked classmates, but I still can’t figure out how to fix it. Has anyone encountered this issue before with ggrepel on polar coordinates? Any suggestions would be greatly appreciated!

Thanks in advance for your help

works for me with

> packageVersion("ggplot2")
[1] ‘4.0.1’
> packageVersion("ggrepel")
[1] ‘0.9.6’
> R.version.string
[1] "R version 4.5.2 (2025-10-31)"