ggplot2 icon indicating copy to clipboard operation
ggplot2 copied to clipboard

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

Open david-romano opened this issue 2 years ago • 2 comments

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)

david-romano avatar Mar 11 '22 15:03 david-romano

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 avatar Mar 14 '22 15:03 hadley

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

javlon avatar Aug 09 '22 00:08 javlon