Repository navigation
Closed
Description
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
thomasp85 commentedon Apr 29, 2019
Can you elaborate on what part is unexpected?
brodieG commentedon 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 theexpand_scale(mult=c(0.05, 0.50)).Suppose you wanted to specify a
coord_cartesianylim, but also wanted non-default scale expansions, how would you do it? AFAICTcoord_cartesianonly allows you to turn expansion on and off, not specify what the expansion values do. That it overrides theexpansionparameter ofscale_y_continuousmeans there is no way to do this other than through hacky re-calculations of theylimvalues.clauswilke commentedon Apr 29, 2019
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 commentedon 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 commentedon May 3, 2019
I doubt it's high on anybody's todo list right now. You can tackle it when you have the time.
paleolimbot commentedon Jun 23, 2019
This appears to be fixed in the master branch, so I am closing:
Created on 2019-06-23 by the reprex package (v0.2.1)
brodieG commentedon Jun 24, 2019
Wonderful, I didn't even have to do anything. Thanks!
lock commentedon 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/