Skip to content

stat_function() produces incorrect warning #3611

Closed
@clauswilke

Description

@clauswilke

stat_function() generates a warning whenever a mapping is provided, but then it uses the mapping as normal.

These are the relevant lines in the code, and a reprex follows below.

# Warn if supplied mapping and/or data is going to be overwritten
if (!is.null(mapping)) {
warning("`mapping` is not used by stat_function()", call. = FALSE)
}

library(ggplot2)

ggplot(data.frame(x = 0), aes(x = x)) +
  stat_function(aes(color = "linear"), fun = function(x) x) +
  stat_function(aes(color = "quadratic"), fun = function(x) x*x) +
  xlim(-5, 5)
#> Warning: `mapping` is not used by stat_function()

#> Warning: `mapping` is not used by stat_function()

Created on 2019-11-04 by the reprex package (v0.3.0)

I'm not sure whether there are cases where the warning is useful. I would propose to delete it. It's probably too complicated to try to find out whether the mapping is meaningful or not in the given context.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions