Skip to content

Can't pipe into qplot with non-auto geom #3670

Closed

Description

@PatrickRobotham

I can plot a histogram with any of:

my_data <- rnorm(100);
qplot(my_data);
qplot(my_data, geom="auto");
qplot(my_data, geom="histogram");

my_data %>% qplot;
my_data %>% qplot(geom="auto");
my_data %>% qplot(geom="auto", x = .);

my_data %>% ggplot(data = data.frame(foo=.), mapping=aes(x = foo)) +
geom_histogram();

I would expect the same behaviour from

my_data %>% qplot(geom="histogram");
my_data %>% qplot(geom="histogram", x = .);

but instead these two fail with

Don't know how to automatically pick scale for object of type list.
Defaulting to continuous
Error in as.data.frame.default(x[[i]], optional = TRUE,
stringsAsFactors = stringsAsFactors) :
  cannot coerce class "c("gg", "ggplot")" to a data.frame

Activity

  1. yutannihilation commented on Dec 18, 2019

    @yutannihilation
    Member

    Curious. But I'm not sure if we can fix this on ggplot2's side...

    library(ggplot2)
    library(magrittr)
    
    my_data <- rnorm(100)
    
    p1 <- qplot(my_data, geom = "histogram")
    p1$mapping$x
    #> <quosure>
    #> expr: ^my_data
    #> env:  global
    
    x1 <- rlang::eval_tidy(p1$mapping$x, env = p1$plot_env)
    is(x1)
    #> [1] "numeric" "vector"
    
    p2 <- my_data %>% qplot(geom = "histogram")
    p2$mapping$x
    #> <quosure>
    #> expr: ^.
    #> env:  0x7fc1bd75dd70
    
    x2 <- rlang::eval_tidy(p2$mapping$x, env = p2$plot_env)
    is(x2)
    #> [1] "list"   "vector"
    
    dput(x2)
    #> list(value = structure(list(data = structure(list(), class = "data.frame", row.names = integer(0)), 
    #>     layers = list(<environment>), scales = <environment>, mapping = structure(list(
    #>         x = ~.), class = "uneval"), theme = list(), coordinates = <environment>, 
    #>     facet = <environment>, plot_env = <environment>, labels = list(
    #>         y = "", x = ".", weight = "weight")), class = c("gg", 
    #> "ggplot")), visible = TRUE)

    Created on 2019-12-18 by the reprex package (v0.3.0)

  2. yutannihilation commented on Dec 18, 2019

    @yutannihilation
    Member

    I guess evaluating x and other data in qplot() might fix this issue, but I'm afraid the change would break other things in other places. So, I don't feel this is worth fixing.

  3. added
    bug
    on Jan 21, 2020
  4. added this to the ggplot2 3.3.4 milestone on Mar 25, 2021
  5. thomasp85 commented on Apr 20, 2021

    @thomasp85
    Member

    Yeah, I agree... This is a wontfix especially considering the status of qplot()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    bug

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions