Skip to content

Consistently use element_grob() or element_render() instead of textGrob() #3557

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
1 of 3 tasks
clauswilke opened this issue Oct 7, 2019 · 5 comments · Fixed by #3683
Closed
1 of 3 tasks

Consistently use element_grob() or element_render() instead of textGrob() #3557

clauswilke opened this issue Oct 7, 2019 · 5 comments · Fixed by #3683
Milestone

Comments

@clauswilke
Copy link
Member

clauswilke commented Oct 7, 2019

There are a few cases where we call textGrob() directly instead of element_grob() or element_render(). Ideally, we should eliminate all of them. Here is a list of cases I'm currently aware of. There may be more. Reprexes will follow below.

  • Axis text for non-standard axis position (e.g., x axis on top)
  • Facet labels when using facet_wrap()
  • Facet labels when using facet_grid()

(Checkmark means the issue has been addressed.)

@clauswilke
Copy link
Member Author

Axis text for non-standard axis position was first reported here: wilkelab/ggtext#5 But now that I'm thinking about it, I think it works fine, so I'll check it off as Ok.

@clauswilke
Copy link
Member Author

Facet labels when using facet_wrap(). First reported here: wilkelab/ggtext#2

library(tidyverse)
library(ggtext)
library(glue)
#> 
#> Attaching package: 'glue'
#> The following object is masked from 'package:dplyr':
#> 
#>     collapse

count(mtcars, cyl, carb) %>% 
  mutate(cyl_lab = as.character(
    glue("Cylinders {cyl} <span style='color:red'>(n={n})</span>")
  )) %>% 
  ggplot(aes(carb, n)) +
  geom_col() +
  facet_wrap(~cyl_lab) +
  theme(
    strip.text = element_markdown(),
    strip.text.x = element_markdown(),
    strip.text.y = element_markdown()
  )

Created on 2019-10-07 by the reprex package (v0.3.0)

@hrbrmstr Anything you'd like to add?

@clauswilke
Copy link
Member Author

The same problem exists in facet_grid().

library(tidyverse)
library(ggtext)
library(glue)
#> 
#> Attaching package: 'glue'
#> The following object is masked from 'package:dplyr':
#> 
#>     collapse

count(mtcars, cyl, carb) %>% 
  mutate(cyl_lab = as.character(
    glue("Cylinders {cyl} <span style='color:red'>(n={n})</span>")
  )) %>% 
  ggplot(aes(carb, n)) +
  geom_col() +
  facet_grid(~cyl_lab) +
  theme(
    strip.text = element_markdown(),
    strip.text.x = element_markdown(),
    strip.text.y = element_markdown()
  )

Created on 2019-10-07 by the reprex package (v0.3.0)

@clauswilke
Copy link
Member Author

Tagging this for the 3.3.0 milestone, with the understanding that it may not be possible to complete by then.

@z3tt
Copy link

z3tt commented Apr 12, 2022

For me rendered facet labels work, boxes could be checked. Thanks once again for this wonderful package!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants