Skip to content

Issue with geom_contour_filled when the z values are too close together #4874

Description

There seems to be a bug in the function geom_contour_filled where it fails in some simple cases.

library(tidyverse)

#Generate some data
data = crossing(x = 1:10, y = 1:10) %>% 
  mutate(z = (x+y)/4)

#Works great
ggplot(data) + geom_contour_filled(aes(x, y, z = z))

#Make a minor tweak and it fails
data2 = data %>% mutate(z = z + 100)
ggplot(data2) + geom_contour_filled(aes(x, y, z = z))
#> Warning: Computation failed in `stat_contour_filled()`:
#> factor level [4] is duplicated

Looking into it, I believe the problem is with the legend names (more specifically the function pretty_isoband_levels). If the z values are close, you can get different levels with the same names because it only uses 3 digits (eg. "(101, 101]" and again "(101, 101]").

Created on 2022-06-14 by the reprex package (v2.0.1)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions