Skip to content

fix title_spec() for vectorized input #3493

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

Merged
merged 5 commits into from
Aug 26, 2019

Conversation

clauswilke
Copy link
Member

This seems to fix #3492.

library(tidyverse)
library(tibble)
ds <- mtcars %>%
  rownames_to_column() %>%
  select(car = rowname, mpg)

ds_size = rep(8, nrow(ds))
ds_size[10] <- 12

ds %>%
  ggplot(aes(x = car, y = mpg)) +
  coord_flip() +
  theme(axis.text.y = element_text(size = ds_size))

Created on 2019-08-19 by the reprex package (v0.3.0)

Session info
devtools::session_info()
#> ─ Session info ──────────────────────────────────────────────────────────
#>  setting  value                       
#>  version  R version 3.6.0 (2019-04-26)
#>  os       macOS Mojave 10.14.5        
#>  system   x86_64, darwin15.6.0        
#>  ui       X11                         
#>  language (EN)                        
#>  collate  en_US.UTF-8                 
#>  ctype    en_US.UTF-8                 
#>  tz       America/Chicago             
#>  date     2019-08-19                  
#> 
#> ─ Packages ──────────────────────────────────────────────────────────────
#>  package     * version    date       lib source        
#>  assertthat    0.2.1      2019-03-21 [1] CRAN (R 3.6.0)
#>  backports     1.1.4      2019-04-10 [1] CRAN (R 3.6.0)
#>  broom         0.5.2      2019-04-07 [1] CRAN (R 3.6.0)
#>  callr         3.3.1      2019-07-18 [1] CRAN (R 3.6.0)
#>  cellranger    1.1.0      2016-07-27 [1] CRAN (R 3.6.0)
#>  cli           1.1.0      2019-03-19 [1] CRAN (R 3.6.0)
#>  colorspace    1.4-1      2019-03-18 [1] CRAN (R 3.6.0)
#>  crayon        1.3.4      2017-09-16 [1] CRAN (R 3.6.0)
#>  curl          4.0        2019-07-22 [1] CRAN (R 3.6.0)
#>  desc          1.2.0      2018-05-01 [1] CRAN (R 3.6.0)
#>  devtools      2.0.2      2019-04-08 [1] CRAN (R 3.6.0)
#>  digest        0.6.20     2019-07-04 [1] CRAN (R 3.6.0)
#>  dplyr       * 0.8.3      2019-07-04 [1] CRAN (R 3.6.0)
#>  evaluate      0.14       2019-05-28 [1] CRAN (R 3.6.0)
#>  forcats     * 0.4.0      2019-02-17 [1] CRAN (R 3.6.0)
#>  fs            1.3.1      2019-05-06 [1] CRAN (R 3.6.0)
#>  generics      0.0.2      2018-11-29 [1] CRAN (R 3.6.0)
#>  ggplot2     * 3.2.1.9000 2019-08-19 [1] local         
#>  glue          1.3.1      2019-03-12 [1] CRAN (R 3.6.0)
#>  gtable        0.3.0      2019-03-25 [1] CRAN (R 3.6.0)
#>  haven         2.1.0      2019-02-19 [1] CRAN (R 3.6.0)
#>  highr         0.8        2019-03-20 [1] CRAN (R 3.6.0)
#>  hms           0.4.2      2018-03-10 [1] CRAN (R 3.6.0)
#>  htmltools     0.3.6      2017-04-28 [1] CRAN (R 3.6.0)
#>  httr          1.4.0      2018-12-11 [1] CRAN (R 3.6.0)
#>  jsonlite      1.6        2018-12-07 [1] CRAN (R 3.6.0)
#>  knitr         1.23       2019-05-18 [1] CRAN (R 3.6.0)
#>  labeling      0.3        2014-08-23 [1] CRAN (R 3.6.0)
#>  lattice       0.20-38    2018-11-04 [1] CRAN (R 3.6.0)
#>  lazyeval      0.2.2      2019-03-15 [1] CRAN (R 3.6.0)
#>  lubridate     1.7.4      2018-04-11 [1] CRAN (R 3.6.0)
#>  magrittr      1.5        2014-11-22 [1] CRAN (R 3.6.0)
#>  memoise       1.1.0      2017-04-21 [1] CRAN (R 3.6.0)
#>  mime          0.7        2019-06-11 [1] CRAN (R 3.6.0)
#>  modelr        0.1.4      2019-02-18 [1] CRAN (R 3.6.0)
#>  munsell       0.5.0      2018-06-12 [1] CRAN (R 3.6.0)
#>  nlme          3.1-140    2019-05-12 [1] CRAN (R 3.6.0)
#>  pillar        1.4.2      2019-06-29 [1] CRAN (R 3.6.0)
#>  pkgbuild      1.0.4      2019-08-05 [1] CRAN (R 3.6.0)
#>  pkgconfig     2.0.2      2018-08-16 [1] CRAN (R 3.6.0)
#>  pkgload       1.0.2      2018-10-29 [1] CRAN (R 3.6.0)
#>  prettyunits   1.0.2      2015-07-13 [1] CRAN (R 3.6.0)
#>  processx      3.4.1      2019-07-18 [1] CRAN (R 3.6.0)
#>  ps            1.3.0      2018-12-21 [1] CRAN (R 3.6.0)
#>  purrr       * 0.3.2      2019-03-15 [1] CRAN (R 3.6.0)
#>  R6            2.4.0      2019-02-14 [1] CRAN (R 3.6.0)
#>  Rcpp          1.0.2      2019-07-25 [1] CRAN (R 3.6.0)
#>  readr       * 1.3.1      2018-12-21 [1] CRAN (R 3.6.0)
#>  readxl        1.3.1      2019-03-13 [1] CRAN (R 3.6.0)
#>  remotes       2.1.0      2019-06-24 [1] CRAN (R 3.6.0)
#>  rlang         0.4.0      2019-06-25 [1] CRAN (R 3.6.0)
#>  rmarkdown     1.13       2019-05-22 [1] CRAN (R 3.6.0)
#>  rprojroot     1.3-2      2018-01-03 [1] CRAN (R 3.6.0)
#>  rvest         0.3.4      2019-05-15 [1] CRAN (R 3.6.0)
#>  scales        1.0.0      2018-08-09 [1] CRAN (R 3.6.0)
#>  sessioninfo   1.1.1      2018-11-05 [1] CRAN (R 3.6.0)
#>  stringi       1.4.3      2019-03-12 [1] CRAN (R 3.6.0)
#>  stringr     * 1.4.0      2019-02-10 [1] CRAN (R 3.6.0)
#>  testthat      2.1.1      2019-04-23 [1] CRAN (R 3.6.0)
#>  tibble      * 2.1.3      2019-06-06 [1] CRAN (R 3.6.0)
#>  tidyr       * 0.8.3      2019-03-01 [1] CRAN (R 3.6.0)
#>  tidyselect    0.2.5      2018-10-11 [1] CRAN (R 3.6.0)
#>  tidyverse   * 1.2.1      2017-11-14 [1] CRAN (R 3.6.0)
#>  usethis       1.5.0      2019-04-07 [1] CRAN (R 3.6.0)
#>  withr         2.1.2      2018-03-15 [1] CRAN (R 3.6.0)
#>  xfun          0.8        2019-06-25 [1] CRAN (R 3.6.0)
#>  xml2          1.2.0      2018-01-24 [1] CRAN (R 3.6.0)
#>  yaml          2.2.0      2018-07-25 [1] CRAN (R 3.6.0)
#> 
#> [1] /Library/Frameworks/R.framework/Versions/3.6/Resources/library

@clauswilke clauswilke force-pushed the issue-3492-vectorized-text branch from ffb285c to 655ef2b Compare August 20, 2019 01:54
@clauswilke clauswilke requested a review from thomasp85 August 20, 2019 01:55
@clauswilke
Copy link
Member Author

I updated my PR so things don't go haywire with multiple angles. There will still be a warning, though. That's beyond the current issue.

library(tidyverse)
library(tibble)
ds <- mtcars %>%
  rownames_to_column() %>%
  select(car = rowname, mpg)

ds_angle = rep(45, nrow(ds))
ds_angle[10] <- -45

ds %>%
  ggplot(aes(x = car, y = mpg)) +
  coord_flip() +
  theme(axis.text.y = element_text(angle = ds_angle))
#> Warning in if (0 <= angle & angle < 90) {: the condition has length > 1 and
#> only the first element will be used

Created on 2019-08-20 by the reprex package (v0.3.0)

@thomasp85
Copy link
Member

As I mentioned in the issue I really don’t think we should support this use in any way. The correct approach is to make sure it never works IMO

@thomasp85
Copy link
Member

Is there a reason why you don't go the full mile and deprecate it properly? Is it too harsh in your opinion?

@clauswilke
Copy link
Member Author

Yes, it's too harsh I think. A lot of people use vectorized input to element_text(), primarily to draw colored axis labels. See e.g. here: https://stackoverflow.com/a/38862452/4975218

We should not disable this option until we have a good alternative in place. Otherwise we just break people's figures without good reason.

@thomasp85
Copy link
Member

Fair enough. We’ll wait until ggtext is ready for prime time and deprecate then

@yutannihilation
Copy link
Member

+1

@clauswilke
Copy link
Member Author

@hadley Should this get a news item?

@hadley
Copy link
Member

hadley commented Aug 26, 2019

Yeah, I think so - it focus on that this isn't a good idea, rather than the fix.

@clauswilke
Copy link
Member Author

How's this?

element_text() now issues a warning when vectorized arguments are provided, as in colour = c("red", "green", "blue"). Such use is discouraged and not officially supported (@clauswilke, #3492).

@hadley
Copy link
Member

hadley commented Aug 26, 2019

LGTM

@clauswilke clauswilke merged commit 49d438c into tidyverse:master Aug 26, 2019
@clauswilke clauswilke deleted the issue-3492-vectorized-text branch August 26, 2019 18:27
@lock
Copy link

lock bot commented Feb 22, 2020

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 Feb 22, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

element_text size using vector
4 participants