-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed as duplicate of#6033
Description
The Alignment section of geom_text
discussing hjust
and vjust
says
... the
vjust
andhjust
aesthetics. These can either be a number between 0 (right/bottom) and 1 (top/left)...
But this is incorrect: hjust = 0
gives left alignment, and hjust = 1
gives right alignment.
As a more minor quibble, it would be good form to maintain a consistent order of (vjust/hjust). Recommend correcting it to
These can either be a number between 0 (bottom/left) and 1 (top/right)...
Quick reprex from this Stack Overflow answer
library(ggplot2)
hjust_data = data.frame(z = paste("hjust =", c(0, 0.5, 1)))
df = data.frame(x = 1:5, y = 1:5)
df = merge(df, hjust_data, all = TRUE)
text_df = subset(df, x == 3) |>
transform(lab = "Your nice\nmultiple line text\nis here")
ggplot(df, aes(x, y)) +
geom_point() +
facet_wrap(vars(z), ncol = 1) +
geom_text(aes(label = lab), data = text_df[1, ], hjust = 0) +
geom_text(aes(label = lab), data = text_df[2, ], hjust = 0.5) +
geom_text(aes(label = lab), data = text_df[3, ], hjust = 1)
Metadata
Metadata
Assignees
Labels
No labels