Skip to content

scale error when setting aes(colour = NULL) #2688

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
ThierryO opened this issue Jun 7, 2018 · 6 comments
Closed

scale error when setting aes(colour = NULL) #2688

ThierryO opened this issue Jun 7, 2018 · 6 comments
Assignees
Labels
bug an unexpected problem or unintended behavior
Milestone

Comments

@ThierryO
Copy link

ThierryO commented Jun 7, 2018

Originally filed as r-lib/scales#125. File again here as requested by @hadley.

The code below used to work. Now it returns the error Error: Discrete value supplied to continuous scale. Is this a bug or a feature?

ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl), fill = factor(cyl))) +
  geom_smooth(method = "lm", aes(fill = NULL, colour = NULL)) +
  geom_point() +
  geom_smooth(method = "lm")

I know it can write the same plot as below. But the code above is more succinct.

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_smooth(method = "lm") +
  geom_point(aes(colour = factor(cyl), fill = factor(cyl))) +
  geom_smooth(method = "lm", aes(colour = factor(cyl), fill = factor(cyl)))
I'm using a development version of `ggplot2` and `scales`
Session info --------------------------------------------------------------------------------------------------
 setting  value                       
 version  R version 3.4.4 (2018-03-15)
 system   x86_64, linux-gnu           
 ui       RStudio (1.1.442)           
 language nl_BE:nl                    
 collate  nl_BE.UTF-8                 
 tz       Europe/Brussels             
 date     2018-06-07                  

Packages ------------------------------------------------------------------------------------------------------
 package      * version    date       source                              
 assertthat     0.2.0      2017-04-11 CRAN (R 3.4.0)                      
 cli            1.0.0      2017-11-05 cran (@1.0.0)                       
 colorspace     1.3-2      2016-12-14 CRAN (R 3.4.0)                      
 crayon         1.3.4      2017-09-16 CRAN (R 3.4.2)                      
 dichromat      2.0-0      2013-01-24 CRAN (R 3.4.0)                      
 digest         0.6.15     2018-02-14 Github (eddelbuettel/digest@d9f40a9)
 ggplot2      * 2.2.1.9000 2018-05-16 Github (hadley/ggplot2@2b0a954)     
 glue           1.2.0      2017-10-29 cran (@1.2.0)                       
 graphics     * 3.4.4      2018-03-16 local                               
 grDevices    * 3.4.4      2018-03-16 local                               
 grid           3.4.4      2018-03-16 local                               
 gtable         0.2.0      2016-02-26 CRAN (R 3.4.0)                      
 labeling       0.3        2014-08-23 CRAN (R 3.4.0)                      
 lattice        0.20-35    2017-03-25 CRAN (R 3.4.1)                      
 lazyeval       0.2.1      2017-10-29 cran (@0.2.1)                       
 magrittr       1.5        2014-11-22 CRAN (R 3.4.0)                      
 MASS           7.3-50     2018-04-30 CRAN (R 3.4.4)                      
 Matrix         1.2-14     2018-04-09 CRAN (R 3.4.4)                      
 methods      * 3.4.4      2018-03-16 local                               
 mgcv           1.8-23     2018-01-15 CRAN (R 3.4.4)                      
 munsell        0.4.3      2016-02-13 CRAN (R 3.4.0)                      
 nlme           3.1-137    2018-04-07 CRAN (R 3.4.4)                      
 pillar         1.2.3      2018-05-25 CRAN (R 3.4.4)                      
 plyr           1.8.4      2016-06-08 CRAN (R 3.4.0)                      
 R6             2.2.2      2017-06-17 CRAN (R 3.4.0)                      
 RColorBrewer   1.1-2      2014-12-07 CRAN (R 3.4.0)                      
 Rcpp           0.12.17    2018-05-18 CRAN (R 3.4.4)                      
 reshape2       1.4.3      2017-12-11 cran (@1.4.3)                       
 rlang          0.2.1      2018-05-30 CRAN (R 3.4.4)                      
 scales         0.5.0.9000 2018-06-05 local                               
 stats        * 3.4.4      2018-03-16 local                               
 stringi        1.2.2      2018-05-02 CRAN (R 3.4.4)                      
 stringr        1.3.1      2018-05-10 CRAN (R 3.4.4)                      
 tibble         1.4.2      2018-01-22 cran (@1.4.2)                       
 tools          3.4.4      2018-03-16 local                               
 utf8           1.1.4      2018-05-24 CRAN (R 3.4.4)                      
 utils        * 3.4.4      2018-03-16 local                               
 viridisLite    0.3.0      2018-02-01 cran (@0.3.0)                       
 withr          2.1.2      2018-03-27 Github (jimhester/withr@79d7b0d)    
@hadley hadley added this to the v2.3.0 milestone Jun 7, 2018
@hadley hadley added the bug an unexpected problem or unintended behavior label Jun 7, 2018
@hadley
Copy link
Member

hadley commented Jun 7, 2018

Likely related to #2599

@lionel- can you please take a quick look? (sometime during WW is fine)

@lionel- lionel- self-assigned this Jun 7, 2018
@lionel-
Copy link
Member

lionel- commented Jun 11, 2018

@ThierryO I can't reproduce this, how recent is your dev ggplot2? Could you try on a fresh master please?

@clauswilke
Copy link
Member

This also works fine for me.

library(ggplot2)
ggplot(mtcars, aes(x = wt, y = mpg, colour = factor(cyl), fill = factor(cyl))) +
  geom_smooth(method = "lm", aes(fill = NULL, colour = NULL)) +
  geom_point() +
  geom_smooth(method = "lm")

Created on 2018-06-11 by the reprex package (v0.2.0).

Session info
devtools::session_info()
#> Session info -------------------------------------------------------------
#>  setting  value                       
#>  version  R version 3.5.0 (2018-04-23)
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  tz       America/Chicago             
#>  date     2018-06-11
#> Packages -----------------------------------------------------------------
#>  package    * version    date       source                          
#>  assertthat   0.2.0      2017-04-11 CRAN (R 3.5.0)                  
#>  backports    1.1.2      2017-12-13 CRAN (R 3.5.0)                  
#>  base       * 3.5.0      2018-04-24 local                           
#>  bindr        0.1.1      2018-03-13 CRAN (R 3.5.0)                  
#>  bindrcpp     0.2        2017-06-17 CRAN (R 3.5.0)                  
#>  colorspace   1.4-0      2017-12-23 R-Forge (R 3.5.0)               
#>  compiler     3.5.0      2018-04-24 local                           
#>  curl         3.1        2017-12-12 CRAN (R 3.5.0)                  
#>  datasets   * 3.5.0      2018-04-24 local                           
#>  devtools     1.13.5     2018-02-18 CRAN (R 3.5.0)                  
#>  digest       0.6.15     2018-01-28 CRAN (R 3.5.0)                  
#>  dplyr        0.7.4      2017-09-28 CRAN (R 3.5.0)                  
#>  evaluate     0.10.1     2017-06-24 CRAN (R 3.5.0)                  
#>  ggplot2    * 2.2.1.9000 2018-06-10 local                           
#>  glue         1.2.0      2017-10-29 CRAN (R 3.5.0)                  
#>  graphics   * 3.5.0      2018-04-24 local                           
#>  grDevices  * 3.5.0      2018-04-24 local                           
#>  grid         3.5.0      2018-04-24 local                           
#>  gtable       0.2.0      2016-02-26 CRAN (R 3.5.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 (R 3.5.0)                  
#>  lazyeval     0.2.1      2017-10-29 CRAN (R 3.5.0)                  
#>  magrittr     1.5        2014-11-22 CRAN (R 3.5.0)                  
#>  memoise      1.1.0      2017-04-21 CRAN (R 3.5.0)                  
#>  methods    * 3.5.0      2018-04-24 local                           
#>  mime         0.5        2016-07-07 CRAN (R 3.5.0)                  
#>  munsell      0.4.3      2016-02-13 CRAN (R 3.5.0)                  
#>  pillar       1.2.1      2018-02-27 CRAN (R 3.5.0)                  
#>  pkgconfig    2.0.1      2017-03-21 CRAN (R 3.5.0)                  
#>  plyr         1.8.4      2016-06-08 CRAN (R 3.5.0)                  
#>  R6           2.2.2      2017-06-17 CRAN (R 3.5.0)                  
#>  Rcpp         0.12.17    2018-05-18 cran (@0.12.17)                 
#>  rlang        0.2.0.9001 2018-05-30 Github (r-lib/rlang@f60976c)    
#>  rmarkdown    1.9        2018-03-01 CRAN (R 3.5.0)                  
#>  rprojroot    1.3-2      2018-01-03 CRAN (R 3.5.0)                  
#>  scales       0.5.0.9000 2018-06-09 local                           
#>  stats      * 3.5.0      2018-04-24 local                           
#>  stringi      1.1.7      2018-03-12 CRAN (R 3.5.0)                  
#>  stringr      1.3.0      2018-02-19 CRAN (R 3.5.0)                  
#>  tibble       1.4.2      2018-01-22 CRAN (R 3.5.0)                  
#>  tools        3.5.0      2018-04-24 local                           
#>  utils      * 3.5.0      2018-04-24 local                           
#>  withr        2.1.2      2018-05-30 Github (jimhester/withr@70d6321)
#>  xml2         1.2.0      2018-01-24 CRAN (R 3.5.0)                  
#>  yaml         2.1.18     2018-03-08 CRAN (R 3.5.0)

@ThierryO
Copy link
Author

I've run the example with both the CRAN version and the current master. It works with those versions.

ggplot2      * 2.2.1      2016-12-30 CRAN (R 3.4.4)
ggplot2      * 2.2.1.9000 2018-06-11 Github (tidyverse/ggplot2@4db5122)  

@lionel-
Copy link
Member

lionel- commented Jun 11, 2018

Great thanks.

@lock
Copy link

lock bot commented Dec 8, 2018

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 8, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug an unexpected problem or unintended behavior
Projects
None yet
Development

No branches or pull requests

4 participants