-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed
Description
I found a problem with the location of labels created by geom_label in the context of polar coordinates.
When I do not use the "fill" argument in geom_label, the labels are located correctly. However, when I set "fill" to a color, the labels appear to swap positions, as though theta had been set to minus theta. I expected fill color and location to be able to be changed independently.
Here is the code to reproduce the bug:
penguin_sum <- penguins %>%
group_by(species) %>%
summarize(y=n(), .groups="drop") %>%
merge(summarize(., N=sum(y))) %>%
mutate(pct=round(100*y/N),
label=paste0("N=", y, "\n(", pct, "%)"))
penguin_sum
# Counts:
# Adelie 152
# Chinstrap 68
# Gentoo 124
# Labels display on correct segment, with Adelie N=152
ggplot(penguin_sum, aes(x="", y=y, fill=species)) +
geom_col(color="white") +
geom_label(aes(label=label), position=position_stack(vjust=0.5)) +
coord_polar(theta="y")
# Labels print in mirror, so it looks like Adelie N=124
ggplot(penguin_sum, aes(x="", y=y, fill=species)) +
geom_col(color="white") +
geom_label(aes(label=label), fill="white", position=position_stack(vjust=0.5)) +
coord_polar(theta="y")
reprex::reprex()Metadata
Metadata
Assignees
Labels
No labels