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

Warning when unsetting an aesthetic that's not used by a geom #1909

Closed
wch opened this issue Nov 14, 2016 · 5 comments
Closed

Warning when unsetting an aesthetic that's not used by a geom #1909

wch opened this issue Nov 14, 2016 · 5 comments

Comments

@wch
Copy link
Member

@wch wch commented Nov 14, 2016

If you add a geom that uses a different data set, and it does not use an aesthetic set in the ggplot() call,

In the example below, I'm adding a geom_linerange() which uses a different data set from the one specified in the ggplot() call. The linerange doesn't have a y aesthetic. Its data set, d2, also doesn't have the yval column which was used in the aesthetic mapping for y at the top level.

If I map aes(y=NULL) in the geom_linerange, it gives a warning that it's ignoring y. If I don't map y, then it errors because it still tries to evaluate the y=yval mapping even though it's not used for that geom.

library(ggplot2)

d <- data.frame(
  xval = 1:2,
  yval = 1:2
)

d2 <- data.frame(
  xval = 3:4,
  yval2 = 3:4
)

p <- ggplot(d, aes(x=xval, y=yval)) +
  geom_point()

p + geom_linerange(aes(y = NULL, ymin = yval2, ymax = yval2+1), data = d2)
#> Warning: Ignoring unknown aesthetics: y

p + geom_linerange(aes(ymin = yval2, ymax = yval2+1), data = d2)
#> Error in eval(expr, envir, enclos) : object 'yval' not found
@hadley
Copy link
Member

@hadley hadley commented Nov 15, 2016

Hmmm, maybe it should not warn for aesthetics set to NULL?

@wch
Copy link
Member Author

@wch wch commented Nov 15, 2016

Is it possible to have it not try to evaluate the unused aesthetic? I think that would be preferable.

@hadley
Copy link
Member

@hadley hadley commented Nov 15, 2016

I don't see how that work work and still preserve the intent of flagging problems like aes(colur = blah)

@andbarker
Copy link

@andbarker andbarker commented Nov 15, 2016

+1 for not warning when the aes is null.
Mainly because it forces you to explicitly stated when there's a dummy aes.

@hadley
Copy link
Member

@hadley hadley commented Jan 27, 2017

@wch maybe I misunderstood your question - there's no need to evaluate the aesthetics because identical(quote(NULL), NULL) is TRUE.

@hadley hadley closed this in 96297bf Jan 27, 2017
@lock lock bot locked as resolved and limited conversation to collaborators Jun 19, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
3 participants