Skip to content

When data=NULL and setting all aesthetics, values get dropped #506

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

Closed
wch opened this issue Apr 19, 2012 · 0 comments
Closed

When data=NULL and setting all aesthetics, values get dropped #506

wch opened this issue Apr 19, 2012 · 0 comments

Comments

@wch
Copy link
Member

wch commented Apr 19, 2012

When data=NULL, it should inherit data, not replace it with a data frame with one row per panel.

# Should have no red points
qplot(mpg, wt, data = mtcars) + geom_point(data = data.frame(), x = 20, y = 3, colour = "red", size = 5, alpha=.1)

# Should have many red points overplotted - presently only has one red point
qplot(mpg, wt, data = mtcars) + geom_point(data = NULL, x = 20, y = 3, colour = "red", size = 5, alpha=.1)

# Should have many red points overplotted in each facet, one for each black point in that facet.
# Presently has only one red point per facet.
qplot(mpg, wt, data = mtcars) + geom_point(data = NULL, x = 20, y = 3, colour = "red", size = 5, alpha=.1) +
  facet_wrap(~cyl)

I think the problem is in compute_aesthetics() in layer.r.

Here are the tests that it should pass (should go in test-empty-data.r):

  # NULL should inherit data
  d <- pdata(ggplot(mtcars, aes(x=mpg, y=wt)) + geom_point() +
    geom_point(data=NULL, x = 20, y = 3, colour = "red", size = 5))
  expect_equal(nrow(d[[1]]), nrow(mtcars))
  expect_equal(nrow(d[[2]]), nrow(mtcars))

  d <- pdata(ggplot(mtcars, aes(x=mpg, y=wt)) + geom_point() +
    geom_point(data=NULL, x = 20, y = 3, colour = "red", size = 5) +
    facet_wrap(~ cyl))
  expect_equal(nrow(d[[1]]), nrow(mtcars))
  expect_equal(nrow(d[[2]]), nrow(mtcars))
  expect_equal(sort(d[[1]]$PANEL), sort(d[[2]]$PANEL))
@hadley hadley closed this as completed in fe42a64 Apr 20, 2012
@lock lock bot locked as resolved and limited conversation to collaborators Jun 20, 2018
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

2 participants