Skip to content

stat_summary and rlang lambda expressions #3568

Closed
@dkahle

Description

@dkahle

While lambda expressions are allowed in stat_function() and a few other places, they aren't in stat_summary() type functions. Example below. Note that the args fun.y, fun.ymin, and fun.ymax are in the dev version fun, fun.min, and fun.max.

library("ggplot2")

df <- data.frame(
  x = c(1, 1, 2, 2, 3, 3),
  y = c(0, 2, 1, 3, 2, 4)
)

ggplot(df, aes(x, y)) +
  stat_summary(
    fun.y = mean,
    fun.ymin = function(y) mean(y) - 1,
    fun.ymax = function(y) mean(y) + 1
  )

ggplot(df, aes(x, y)) +
  stat_summary(
    fun.y = mean,
    fun.ymin = ~ mean(.x) - 1,
    fun.ymax = ~ mean(.x) + 1
  )
#> Warning: Computation failed in `stat_summary()`:
#> 'what' must be a function or character string

Created on 2019-10-14 by the reprex package (v0.3.0)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions