-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Closed as not planned
Closed as not planned
Copy link
Labels
Description
We're taking the following figure out of R4DS to save space and thought it might be a useful addition to https://ggplot2.tidyverse.org/articles/ggplot2-specs.html.
#| label: fig-just
#| echo: false
#| fig-width: 4.5
#| fig-asp: 0.5
#| out-width: "60%"
#| fig-cap: >
#| All nine combinations of `hjust` and `vjust`.
#| fig-alt: >
#| A 1x1 grid. At (0,0) hjust is set to left and vjust is set to bottom.
#| At (0.5, 0) hjust is center and vjust is bottom and at (1, 0) hjust is
#| right and vjust is bottom. At (0, 0.5) hjust is left and vjust is
#| center, at (0.5, 0.5) hjust is center and vjust is center, and at (1, 0.5)
#| hjust is right and vjust is center. Finally, at (1, 0) hjust is left and
#| vjust is top, at (0.5, 1) hjust is center and vjust is top, and at (1, 1)
#| hjust is right and vjust is bottom.
vjust <- c(bottom = 0, center = 0.5, top = 1)
hjust <- c(left = 0, center = 0.5, right = 1)
df <- crossing(hj = names(hjust), vj = names(vjust)) |>
mutate(
y = vjust[vj],
x = hjust[hj],
label = paste0("hjust = '", hj, "'\n", "vjust = '", vj, "'")
)
ggplot(df, aes(x, y)) +
geom_point(color = "grey70", size = 5) +
geom_point(size = 0.5, color = "red") +
geom_text(aes(label = label, hjust = hj, vjust = vj), size = 4) +
labs(x = NULL, y = NULL)