Skip to content

Stack divide zero #6341

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Mar 25, 2025
Merged

Stack divide zero #6341

merged 3 commits into from
Mar 25, 2025

Conversation

teunbrand
Copy link
Collaborator

This PR aims to fix #6338.

Briefly, it prevents position_fill() from "filling" when all observations are zero, which would previously generate NAs through division by zero.

Reprex from the issue, note the lack of warning about missing values:

devtools::load_all("~/packages/ggplot2/")
#> ℹ Loading ggplot2

df <-
  tibble::tribble(
    ~season,   ~family, ~count,
    "Summer",    "Bird",    10,
    "Summer",    "Fish",    12,
    "Winter",    "Bird",     4,
    "Winter",    "Fish",     1
  )

df |>
  ggplot(aes(x = season, y = count, fill = family, group = family)) +
  geom_area(position = position_fill())

Created on 2025-02-19 with reprex v2.1.1

Copy link
Member

@thomasp85 thomasp85 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@teunbrand teunbrand merged commit 252e3c0 into tidyverse:main Mar 25, 2025
12 of 13 checks passed
@teunbrand teunbrand deleted the stack_divide_zero branch March 25, 2025 14:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

New warning missing values or values outside the scale range with geom_area(position = position_fill())
2 participants