Skip to content

sec_axis seems to break with tidy evaluation #2788

Closed
@TylerGrantSmith

Description

@TylerGrantSmith

I am trying to add a transformed secondary axis in a function which is using quasiquotations, but sec_axis errors saying that it can't find one of the quoted variables. This only happens when changing trans from its default ~.. For example, dup_axis works fine. reprex included below.

library(tidyverse)
#> -- Attaching packages ------------------------------- tidyverse 1.2.1 --
#> v ggplot2 3.0.0     v purrr   0.2.4
#> v tibble  1.4.2     v dplyr   0.7.6
#> v tidyr   0.8.1     v stringr 1.3.1
#> v readr   1.1.1     v forcats 0.2.0
#> -- Conflicts ---------------------------------- tidyverse_conflicts() --
#> x dplyr::filter() masks stats::filter()
#> x dplyr::lag()    masks stats::lag()

f <- function(df, .x, .y, .z) {
  x<-enquo(.x)
  y<-enquo(.y)
  z<-enquo(.z)
  
  g <- ggplot(df,aes(x=!!x,y=!!y)) + 
    geom_bar(stat="identity") + 
    geom_point(aes(y=!!z)) +
    scale_y_continuous(sec.axis = sec_axis(~./10))

  g
}

t <- tibble(x = letters, y = seq(10,260, 10), z = 1:26)

f(t, x, y, z)
#> Error in as.list.environment(x, all.names = TRUE): object 'x' not found

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