Better error messages for incorrect aesthetic mappings #3060
I encountered some cryptic error messages that pop up in response to fairly normal user mistakes, where the user maps an aesthetic to a data column that doesn't exist. A better error message could help a lot here.
My code example below first shows the desired output and then two incorrect ways in which a user might try to generate it.
library(ggplot2) # desired plot ggplot(mtcars, aes(mpg, 1)) + geom_tile(aes(fill = stat(density)), stat = "density") + geom_point(position = "jitter")
# wrong, `fill` aesthetic mapped to stat-generated data column that # doesn't exist in `geom_point()` layer ggplot(mtcars, aes(mpg, 1, fill = stat(density))) + geom_tile(stat = "density") + geom_point(position = "jitter") #> Error in is.finite(x): default method not implemented for type 'closure' # wrong, `fill` aesthetic mapped to data column that doesn't exist ggplot(mtcars, aes(mpg, 1, fill = density)) + geom_tile(stat = "density") + geom_point(position = "jitter") #> Don't know how to automatically pick scale for object of type function. Defaulting to continuous. #> Error: Column `fill` must be a 1d atomic vector or a list
Created on 2019-01-07 by the reprex package (v0.2.1)
The text was updated successfully, but these errors were encountered:
* Clearer error messages for invalid aesthetics Fixes #3060 * closes #3060 * Modified error messages, fixed spacing, right line endings * Replace use of deparse with rlang::as_label * Fix NEWS mispelling and punctuation. layer.R format suggestions * Left in merge >>>, removed * Remove punctuation in test-layer.R that was failing * Add support for multiple problematic aesthetics, fix NEWS.md addition * Change error to display whole problematic phrase, like fill = density * Update tests to be more specific * Fix failing tests, ideally * Another go at test passing * expect_error uses regex, so ( caused failing. Added fixed = TRUE