Skip to content

Adding limits that contain all data to a histogram generates incorrect missing values warning (due to #2719) #3265

@jmarshallnz

Description

@jmarshallnz

This seems to have been introduced in 3.1.1 - it does not occur in 3.0.0. I haven't verified completely but I believe it's due to #2719.

Adding scale_x_continuous/xlim to specify limits where all data are contained results in a warning that is incorrect (as no data are missing). The problem is the transformed data (i.e. the bars, xmin/xmax etc) are outside the specified limits, as they are computed using the limits (+/- width). This makes the error quite confusing! The plot is fine - no data are missing as the missing bars contain no data.

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 3.5.2
set.seed(2)
d <- data.frame(x=runif(1000))
g <- ggplot(d, aes(x=x)) + geom_histogram(bins=10)
g

g + scale_x_continuous(limits=c(-1,2))
#> Warning: Removed 2 rows containing missing values (geom_bar).

Created on 2019-04-24 by the reprex package (v0.2.1)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions