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

Full-width by default? #35

Open
z3tt opened this issue Aug 4, 2024 · 2 comments
Open

Full-width by default? #35

z3tt opened this issue Aug 4, 2024 · 2 comments

Comments

@z3tt
Copy link

z3tt commented Aug 4, 2024

Hey Thomas,

Thanks for another awesome package! I noticed that element_marquee() requires a width to be specified when passing images only, which means the value must be adjusted whenever the plot width changes.

library(ggplot2)
library(marquee)

logo <- system.file("help", "figures", "logo.png", package = "marquee")
md <- marquee_glue("![]({logo})")

p <- ggplot(mtcars) + 
  geom_point(aes(x = mpg, y = disp)) + 
  labs(caption = md)

## works
p + theme(plot.caption = element_marquee(width = unit(15, "cm")))

## doesn't show the image (guess because width = 0?)
p + theme(plot.caption = element_marquee())

Is there any chance to modify its behavior so that the width is automatically set according to the plot aspect ratio in case the user doesn’t specify a width?

@aphalo
Copy link

aphalo commented Aug 5, 2024

Have you tried using NPC units? The code below seems to work.

## works?
p + theme(plot.caption = element_marquee(width = unit(0.5, "npc")))

@z3tt
Copy link
Author

z3tt commented Aug 6, 2024

Hi @aphalo, thanks for the tip! This helps quite a lot.

However it is not spanning the full plot width by setting width = unit(1, "npc") (also makes sense as it's referring to the panel width). So in case it's possible, I think it still would be nice if the image spans the full plot width by default as the width of the axis label and the legend are influencing the width one needs to specify.

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

2 participants