Skip to content

text rendered incorrrectly when size and justification parameters are supplied to geom_label() #4753

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
david-romano opened this issue Mar 11, 2022 · 2 comments · Fixed by #5030
Labels
bug an unexpected problem or unintended behavior layers 📈

Comments

@david-romano
Copy link

I posted about this in the RStudio Discourse forum, but didn't explicitly point out the effect of supplying the size parameter. Have received no responses so am posting here.

The problem appears to be an interaction between the size parameter of geom_label() and how the justification parameter values are applied to the text itself, but is not apparent unless off-center justification is supplied.

library(tidyverse)

tibble() %>% 
  ggplot() +
  geom_label(aes(0, 0, label = 'text'), 
             hjust = 0,
             size = 20,
             )

Created on 2022-03-11 by the reprex package (v2.0.1)

@hadley
Copy link
Member

hadley commented Mar 14, 2022

Slightly more minimal reprex:

library(ggplot2)

ggplot() +
  annotate("label",
    x = 0, 
    y = 0, 
    label = "text",
    hjust = c(0, 1),
    size = 20,
  )

Created on 2022-03-14 by the reprex package (v2.0.1)

@hadley hadley added bug an unexpected problem or unintended behavior layers 📈 labels Mar 14, 2022
@javlon
Copy link
Contributor

javlon commented Aug 9, 2022

I think this information might be useful.
Text renders correctly if you rewrite the default label.padding unit. The problem occurs with units "lines" and "char", other units seem to be working fine.

library(ggplot2)

ggplot() +
  annotate("label",
           x = 0, 
           y = 0, 
           label = "text",
           hjust = c(0, 1),
           size = 20,
           label.padding=unit(0.5, "cm")
  )

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug an unexpected problem or unintended behavior layers 📈
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants