Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Behavior of hjust = c(0, 1) in ggtext::element_markdown() is different from that of ggplot2::element_text() #116

Open
balthasars opened this issue May 14, 2024 · 1 comment

Comments

@balthasars
Copy link

balthasars commented May 14, 2024


I'm trying to profit from ggtext's more generous behavior of vectorized input to element_text() to plot multiple subtitles on the same line (see f.e. here).

I'm wondering about the behavior of hjust = c(0, 1) in element_markdown() however, that deviates from the ggplot2-native element_text() function:

library(ggplot2)
gg <- ggplot(data = mtcars, aes(x = disp, y = mpg)) +
  geom_line() +
  labs(subtitle = c("left-aligned subtitle", "right-aligned subtitle"))

# ggplot2 version
gg +
  theme(
    plot.subtitle = element_text(hjust = c(0, 1)) 
  )
#> Warning: Vectorized input to `element_text()` is not officially supported.
#> ℹ Results may be unexpected or may change in future versions of ggplot2.

# ggtext
# how I was expecting it to work
gg +
  theme(
    plot.subtitle = ggtext::element_markdown(hjust = c(0, 1))
  )

# how it actually worked
gg +
  theme(
    plot.subtitle = ggtext::element_markdown(hjust = c(1, 5))
  )

Created on 2024-05-14 with reprex v2.1.0

Thanks in advance for any pointers! :)

@balthasars balthasars changed the title `hjust = c(0, 1) Behavior of hjust = c(0, 1) of ggtext::element_markdown() is different from that of ggplot2::element_text() May 14, 2024
@balthasars balthasars changed the title Behavior of hjust = c(0, 1) of ggtext::element_markdown() is different from that of ggplot2::element_text() Behavior of hjust = c(0, 1) in ggtext::element_markdown() is different from that of ggplot2::element_text() May 14, 2024
@balthasars
Copy link
Author

balthasars commented May 29, 2024

I'd be happy do a PR and improve the documentation @bwiernik if hjust = c(1, 5) is how it should work.

Also had a quick look at the source code (also for richtext_grob()) from gridtext but it wasn't immediately clear to me what the arguments should be to get the vectorized input working as demonstrated above,

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant