Skip to content

Current development version breaks compatibility with scale() output, e.g. in qq-plots #2374

Closed

Description

@jemus42

Supplying scale()- standardised values to e.g. the sample aesthetic for the use of qq-plots does work in the current CRAN version, however, it does not work anymore with the current GitHub version.
I looked through the NEWS.md to find any mention of a possible breaking change, but could not find anything that seemed to indicate that this change is intended.

Previous behavior:

# install.packages("ggplot2")

library(ggplot2)
ggplot(data = mtcars, aes(sample = scale(mpg))) +
  geom_qq()

Works fine.

Behavior with current GitHub version:

# devtools::install_github("tidyverse/ggplot2")

library(ggplot2)
ggplot(data = mtcars, aes(sample = scale(mpg))) +
  geom_qq()

# Error: Column `sample` must be a 1d atomic vector or a list

I'm aware that scale returns a 1d-matrix instead of an atomic vector, so I know I can circumvent this issue by using as.numeric(scale(mpg)), but this is simply a case of not wanting to change old code if I don't have to.

Tested versions of ggplot:

  • CRAN: ggplot2 * 2.2.1 2016-12-30 CRAN (R 3.4.0)
  • GitHub: ggplot2 * 2.2.1.9000 2017-12-18 Github (tidyverse/ggplot2@bfff1d8)

Activity

  1. batpigandme commented on Jan 6, 2018

    @batpigandme
    Member

    As you can see below, the difference between scale(mtcars$mpg) and as.numeric(scale(mtcars$mpg)) is that the former includes attributes (scaled:center, and scaled:scale), while the latter does not.

    scale itself is actually comes from base, so I don't think it's something that can be changed here.

    edit: I'm now realizing what you're saying is that sample used to be able to take a scale object. Is that correct?

    scale(mtcars$mpg)
    #>              [,1]
    #>  [1,]  0.15088482
    #>  [2,]  0.15088482
    #>  [3,]  0.44954345
    #>  [4,]  0.21725341
    #>  [5,] -0.23073453
    #>  [6,] -0.33028740
    #>  [7,] -0.96078893
    #>  [8,]  0.71501778
    #>  [9,]  0.44954345
    #> [10,] -0.14777380
    #> [11,] -0.38006384
    #> [12,] -0.61235388
    #> [13,] -0.46302456
    #> [14,] -0.81145962
    #> [15,] -1.60788262
    #> [16,] -1.60788262
    #> [17,] -0.89442035
    #> [18,]  2.04238943
    #> [19,]  1.71054652
    #> [20,]  2.29127162
    #> [21,]  0.23384555
    #> [22,] -0.76168319
    #> [23,] -0.81145962
    #> [24,] -1.12671039
    #> [25,] -0.14777380
    #> [26,]  1.19619000
    #> [27,]  0.98049211
    #> [28,]  1.71054652
    #> [29,] -0.71190675
    #> [30,] -0.06481307
    #> [31,] -0.84464392
    #> [32,]  0.21725341
    #> attr(,"scaled:center")
    #> [1] 20.09062
    #> attr(,"scaled:scale")
    #> [1] 6.026948
    
    
    as.numeric(scale(mtcars$mpg))
    #>  [1]  0.15088482  0.15088482  0.44954345  0.21725341 -0.23073453
    #>  [6] -0.33028740 -0.96078893  0.71501778  0.44954345 -0.14777380
    #> [11] -0.38006384 -0.61235388 -0.46302456 -0.81145962 -1.60788262
    #> [16] -1.60788262 -0.89442035  2.04238943  1.71054652  2.29127162
    #> [21]  0.23384555 -0.76168319 -0.81145962 -1.12671039 -0.14777380
    #> [26]  1.19619000  0.98049211  1.71054652 -0.71190675 -0.06481307
    #> [31] -0.84464392  0.21725341
    library(ggplot2)
    ggplot(data = mtcars, aes(sample = scale(mpg))) +
      geom_qq()
    #> Error: Column `sample` must be a 1d atomic vector or a list
    
    ggplot(data = mtcars, aes(sample = as.numeric(scale(mpg)))) +
      geom_qq()


    Created on 2018-01-06 by the reprex package (v0.1.1.9000).

  2. jemus42 commented on Jan 6, 2018

    @jemus42
    ContributorAuthor

    Thanks @batpigandme, yes, the whole point of my issue here is that this used to be possible as of the latest CRAN version, but it's not anymore in the current dev version.

    I merely want to make sure that this breaking change (well, minor annoyance I guess) is known and intended, rather than this being an accident.

  3. added
    bug
    on Apr 26, 2018
  4. added this to the milestone on Apr 26, 2018
  5. hadley commented on May 1, 2018

    @hadley
    Member

    This is deliberate as ggplot2 now uses as.data.frame(tibble::as_tibble(evaled)) to construct data frames internally - this ensures that we use a consistent (and safe) of creating data frames, and avoids a set of bugs that kept arising in various forms. I think the best resolution is to advertise this in the news.

  6. hadley commented on May 1, 2018

    @hadley
    Member

    Exploring a bit more - more precisely this enables ggplot2 to support list-cols at the expense of matrix-cols.

  7. lock commented on Oct 28, 2018

    @lock

    This old issue has been automatically locked. If you believe you have found a related problem, please file a new issue (with reprex) and link to this issue. https://reprex.tidyverse.org/

  8. locked and limited conversation to collaborators on Oct 28, 2018
  9. added a commit that references this issue on Apr 1, 2026
    b2cf508
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

    buglayers 📈

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions