Skip to content
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

ggplot removing data without warnings #2879

Closed
statsandthings opened this issue Sep 4, 2018 · 5 comments
Closed

ggplot removing data without warnings #2879

statsandthings opened this issue Sep 4, 2018 · 5 comments

Comments

@statsandthings
Copy link

@statsandthings statsandthings commented Sep 4, 2018

Here's a data frame with dates and some random data.

library(tidyverse)
dat <- tibble(
  date = as.Date(40100:40129, origin = "1899-12-30"), 
  rainfall = rnorm(30, 4)
)

When you plot the data the 30th value is not included on the graph. Once you execute the code notice that there is no bar above the date 2009-11-12. I'd also expect a warning in my console that data was removed from the plot, not sure why I don't get one.

ggplot(dat, aes(date, rainfall)) + 
  geom_bar(stat = "identity", fill = "white", color = "grey35") + 
  theme_minimal() + 
  theme(axis.title.x = element_blank(), axis.text.x = element_text(angle=90)) + 
  scale_x_date(
    date_breaks = "1 day",
    limits = c(min(dat$date), max(dat$date))
  ) +  
  NULL
@yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Sep 4, 2018

Generally, this issue is not limited to the cases with date, but seems to happen when plotting geom_bar() on a continous scale with the limits specified.

Here's a minimal reprex to show what happens. The reason why the most right and left bars disappear is that they are beyond the limits and the default oob removes them. But, I think it does warn, don't it...?

You can change the behaviour by specifying oob. But, I couldn't find a good way to ensure that the plot range contains the whole shapes of data.

library(ggplot2)

d <- data.frame(x = 1:5, y = 1:5)

p <- ggplot(d, aes(x, y)) + geom_col()

p + scale_x_continuous(limits = c(1, 5))
#> Warning: Removed 2 rows containing missing values (geom_col).

p + scale_x_continuous(limits = c(1, 5), oob = scales::squish)

Created on 2018-09-05 by the reprex package (v0.2.0).

@clauswilke
Copy link
Member

@clauswilke clauswilke commented Sep 4, 2018

If it is related to #2715 then the warning was added only after 3.0.0 was released.

@clauswilke
Copy link
Member

@clauswilke clauswilke commented Sep 4, 2018

Reprex of the original code example. There's a warning in the current development branch.

library(tidyverse)

dat <- tibble(
  date = as.Date(40100:40129, origin = "1899-12-30"), 
  rainfall = rnorm(30, 4)
)

ggplot(dat, aes(date, rainfall)) + 
  geom_bar(stat = "identity") + 
  scale_x_date(
    date_breaks = "1 day",
    limits = c(min(dat$date), max(dat$date))
  )
#> Warning: Removed 2 rows containing missing values (geom_bar).

Created on 2018-09-04 by the reprex package (v0.2.0).

@yutannihilation
Copy link
Member

@yutannihilation yutannihilation commented Sep 4, 2018

Ah, thanks! I didn't notice the change...

@lock
Copy link

@lock lock bot commented Mar 3, 2019

This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

@lock lock bot locked and limited conversation to collaborators Mar 3, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants