Skip to content

Number of bins off by one in geom_contour() #3879

Closed
@clauswilke

Description

@clauswilke

If we explicitly provide a number of bins, we get one too few. This is particularly striking if we set bins = 2, since that removes all contouring. This example of an empty plot is currently on the ggplot2 website (scroll down to 4th example):
https://ggplot2.tidyverse.org/reference/geom_contour.html#examples

I assume this is a regression introduced in 3.3.0.

library(ggplot2)

p <- ggplot(faithfuld, aes(waiting, eruptions, z = density))

p + geom_contour(bins = 3)

p + geom_contour_filled(bins = 3, aes(fill = after_stat(ordered(piece)))) + 
  scale_fill_viridis_d()

p + geom_contour(bins = 6)

p + geom_contour_filled(bins = 6, aes(fill = after_stat(ordered(piece)))) + 
  scale_fill_viridis_d()

Created on 2020-03-09 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions