Skip to content

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

Closed

Description

@clauswilke

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.)

Activity

  1. clauswilke commented on Oct 7, 2019

    @clauswilke
    MemberAuthor

    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.

  2. clauswilke commented on Oct 7, 2019

    @clauswilke
    MemberAuthor

    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?

  3. clauswilke commented on Oct 7, 2019

    @clauswilke
    MemberAuthor

    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)

  4. added this to the ggplot2 3.3.0 milestone on Dec 17, 2019
  5. clauswilke commented on Dec 17, 2019

    @clauswilke
    MemberAuthor

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

  6. z3tt commented on Apr 12, 2022

    @z3tt

    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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions