ggplot2
ggplot2 copied to clipboard
text rendered incorrrectly when size and justification parameters are supplied to geom_label()
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)
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)
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")
)