Skip to content

Scale expand value from scales ignored when coord_cartesian ylim is used #3270

Closed

Description

@brodieG

It would be desirable to be able to specify 'expand' values in conjunction with coord_cartesian(ylim=...). That does not appear to work, as the expand values are reverted back to defaults. If you agree the current behavior is unexpected I can look into a PR.

library(ggplot2)
p <- ggplot(data.frame(x='a', y=100)) +
  geom_col(aes(x, y)) +
  scale_y_continuous(expand=expand_scale(mult=c(0.05, 0.50)))
p + ggtitle('Simple')

p + ggtitle('w/ coord_cart lim') +
  coord_cartesian(ylim=c(0, 100))

p + ggtitle('w/ coord_cart lim expand false') +
  coord_cartesian(ylim=c(0, 100), expand=FALSE)

Created on 2019-04-24 by the reprex package (v0.2.1)

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.3 (2019-03-11)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2019-04-24
#> Packages -----------------------------------------------------------------
#>  package    * version date       source                         
#>  assertthat   0.2.1   2019-03-21 CRAN (R 3.5.2)                 
#>  backports    1.1.2   2017-12-13 CRAN (R 3.5.0)                 
#>  base       * 3.5.3   2019-03-13 local                          
#>  colorspace   1.3-2   2016-12-14 cran (@1.3-2)                  
#>  compiler     3.5.3   2019-03-13 local                          
#>  crayon       1.3.4   2017-09-16 CRAN (R 3.5.0)                 
#>  curl         3.2     2018-03-28 CRAN (R 3.5.0)                 
#>  datasets   * 3.5.3   2019-03-13 local                          
#>  devtools     1.13.6  2018-06-27 CRAN (R 3.5.0)                 
#>  digest       0.6.18  2018-10-10 cran (@0.6.18)                 
#>  dplyr        0.8.0.1 2019-02-15 CRAN (R 3.5.2)                 
#>  evaluate     0.10.1  2017-06-24 CRAN (R 3.5.0)                 
#>  ggplot2    * 3.1.1   2019-04-07 CRAN (R 3.5.2)                 
#>  glue         1.3.0   2018-08-27 Github (tidyverse/glue@4e74901)
#>  graphics   * 3.5.3   2019-03-13 local                          
#>  grDevices  * 3.5.3   2019-03-13 local                          
#>  grid         3.5.3   2019-03-13 local                          
#>  gtable       0.2.0   2016-02-26 cran (@0.2.0)                  
#>  htmltools    0.3.6   2017-04-28 CRAN (R 3.5.0)                 
#>  httr         1.3.1   2017-08-20 CRAN (R 3.5.0)                 
#>  knitr        1.20    2018-02-20 CRAN (R 3.5.0)                 
#>  labeling     0.3     2014-08-23 cran (@0.3)                    
#>  lazyeval     0.2.1   2017-10-29 cran (@0.2.1)                  
#>  magrittr     1.5     2014-11-22 cran (@1.5)                    
#>  memoise      1.1.0   2017-04-21 CRAN (R 3.5.0)                 
#>  methods    * 3.5.3   2019-03-13 local                          
#>  mime         0.5     2016-07-07 CRAN (R 3.5.0)                 
#>  munsell      0.5.0   2018-06-12 cran (@0.5.0)                  
#>  pillar       1.3.1   2018-12-15 CRAN (R 3.5.0)                 
#>  pkgconfig    2.0.2   2018-08-16 cran (@2.0.2)                  
#>  plyr         1.8.4   2016-06-08 cran (@1.8.4)                  
#>  purrr        0.3.2   2019-03-15 CRAN (R 3.5.2)                 
#>  R6           2.3.0   2018-10-04 cran (@2.3.0)                  
#>  Rcpp         1.0.1   2019-03-17 CRAN (R 3.5.2)                 
#>  rlang        0.3.1   2019-01-08 CRAN (R 3.5.2)                 
#>  rmarkdown    1.10    2018-06-11 CRAN (R 3.5.0)                 
#>  rprojroot    1.3-2   2018-01-03 CRAN (R 3.5.0)                 
#>  scales       1.0.0   2018-08-09 cran (@1.0.0)                  
#>  stats      * 3.5.3   2019-03-13 local                          
#>  stringi      1.2.3   2018-06-12 cran (@1.2.3)                  
#>  stringr      1.3.1   2018-05-10 cran (@1.3.1)                  
#>  tibble       2.1.1   2019-03-16 CRAN (R 3.5.2)                 
#>  tidyselect   0.2.5   2018-10-11 CRAN (R 3.5.0)                 
#>  tools        3.5.3   2019-03-13 local                          
#>  utils      * 3.5.3   2019-03-13 local                          
#>  withr        2.1.2   2018-03-15 CRAN (R 3.5.0)                 
#>  xml2         1.2.0   2018-01-24 CRAN (R 3.5.0)                 
#>  yaml         2.2.0   2018-07-25 CRAN (R 3.5.0)

Activity

  1. thomasp85 commented on Apr 29, 2019

    @thomasp85
    Member

    Can you elaborate on what part is unexpected?

  2. brodieG commented on Apr 29, 2019

    @brodieG
    ContributorAuthor

    Once I specify coord_cartesian(ylim=c(0,100)) the axis expansion goes back to its default value of 0.05, ignoring the expand_scale(mult=c(0.05, 0.50)).

    Suppose you wanted to specify a coord_cartesian ylim, but also wanted non-default scale expansions, how would you do it? AFAICT coord_cartesian only allows you to turn expansion on and off, not specify what the expansion values do. That it overrides the expansion parameter of scale_y_continuous means there is no way to do this other than through hacky re-calculations of the ylim values.

  3. clauswilke commented on Apr 29, 2019

    @clauswilke
    Member

    I think this is a reasonable feature request. Not sure about the best API, though. Is it appropriate for the coord to look up the expansion factors specified in the scale? I guess it's similar to looking up breaks and labels, so maybe that's the best way to go.

  4. brodieG commented on May 3, 2019

    @brodieG
    ContributorAuthor

    Will you guys consider a PR for this then, or do you want to address it yourselves? I can do it, but might be a little while before I get to it.

  5. clauswilke commented on May 3, 2019

    @clauswilke
    Member

    I doubt it's high on anybody's todo list right now. You can tackle it when you have the time.

  6. added
    feature
    on May 21, 2019
  7. paleolimbot commented on Jun 23, 2019

    @paleolimbot
    Member

    This appears to be fixed in the master branch, so I am closing:

    library(ggplot2)
    p <- ggplot(data.frame(x='a', y=100)) +
      geom_col(aes(x, y)) +
      scale_y_continuous(expand=expand_scale(mult=c(0.05, 0.50)))
    
    p + ggtitle('Simple')

    p + ggtitle('w/ coord_cart lim') +
      coord_cartesian(ylim=c(0, 100))

    p + ggtitle('w/ coord_cart lim expand false') +
      coord_cartesian(ylim=c(0, 100), expand=FALSE)

    Created on 2019-06-23 by the reprex package (v0.2.1)

  8. brodieG commented on Jun 24, 2019

    @brodieG
    ContributorAuthor

    Wonderful, I didn't even have to do anything. Thanks!

  9. lock commented on Dec 21, 2019

    @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/

  10. locked and limited conversation to collaborators on Dec 21, 2019
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

    coord 🗺️feature

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions