If I use geom_text()
with hjust
and vjust
parameters, I get the behavior I expect:
library(tidyverse)
tibble(x = 0, y = 0) %>%
ggplot() +
geom_point(aes(x, y)) +
geom_text(aes(x, y, label = 'Text'), size = 20)
tibble(x = 0, y = 0) %>%
ggplot() +
geom_point(aes(x, y)) +
geom_text(
aes(x, y, label = 'Text'), size = 20,
hjust = 0,
vjust = 0,
)
Created on 2022-03-07 by the reprex package (v2.0.1)
But if I replace geom_text()
with geom_label()
(and change opacity so the point at origin is still visible), I get unexpected behavior:
library(tidyverse)
tibble(x = 0, y = 0) %>%
ggplot() +
geom_point(aes(x, y)) +
geom_label(aes(x, y, label = 'Text'), size = 20, alpha = 0.5)
tibble(x = 0, y = 0) %>%
ggplot() +
geom_point(aes(x, y)) +
geom_label(
aes(x, y, label = 'Text'), size = 20, alpha = 0.5,
hjust = 0,
vjust = 0,
)
Created on 2022-03-07 by the reprex package (v2.0.1)
Why is the text rendered outside its bounding box?