Skip to content

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

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
brodieG opened this issue Apr 24, 2019 · 8 comments
Closed
Labels
coord 🗺️ feature a feature request or enhancement

Comments

@brodieG
Copy link
Contributor

brodieG commented Apr 24, 2019

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)
@thomasp85
Copy link
Member

Can you elaborate on what part is unexpected?

@brodieG
Copy link
Contributor Author

brodieG commented Apr 29, 2019

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.

@clauswilke
Copy link
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.

@brodieG
Copy link
Contributor Author

brodieG commented May 3, 2019

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.

@clauswilke
Copy link
Member

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

@paleolimbot
Copy link
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)

@brodieG
Copy link
Contributor Author

brodieG commented Jun 24, 2019

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

@lock
Copy link

lock bot commented Dec 21, 2019

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/

@lock lock bot locked and limited conversation to collaborators Dec 21, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
coord 🗺️ feature a feature request or enhancement
Projects
None yet
Development

No branches or pull requests

4 participants