-
Notifications
You must be signed in to change notification settings - Fork 8
Description
Hi Thomas, thank you for creating marquee. It has expanded the world of possibilities for plotting images and plots inside of plots, so it is very exciting to explore.
Teun started a pull request for a new ggrepel function that uses marquee, so I had to spend some time trying to learn how to use it.
I hope it is ok that I am creating an issue here to document what I have learned.
I wrote these examples in the hope that others would find them helpful.
The main goal of this series of examples is to try multiple ways of
changing the size of an image that is included in a
geom_marquee()
grob.
It seems that omitting width
fails to render the image
(Example 1) when written like "![]()"
. However, if we
specify width
, the image is rendered (Example 4) and we can
scale the image (Example 4) by using different values for
width
.
In contrast, omitting width
is OK when we render an
image written like "{.p ![]()}"
(Example 2), but then the
image cannot be scaled (Example 3) with the width
argument.
Instead of scaling the image, the width
argument is scaling
the container that holds the image.
Teun showed me that we can scale an image written like
"{.p ![]()}"
by writing it like this:
"{.30 {.p ![]()}}"
where 30
indicates some
width (Example 3).
In Example 5, I try to compare the width
argument to the
{.150 {.p ![]()}}
syntax. I find that the .150
syntax is not equivalent to unit(150, "points")
, so I’m not
sure what units 150 is expressing.
I hope this helps others to explore and understand how to use marquee!
If you have more tips, please feel free to share them here.
library(ggplot2)
library(marquee)
Example 1
Should this work? Or is the failure expected?
d <- data.frame(x = 1, y = 1, label = "")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label))
#> Error in grid.Call.graphics(C_raster, x$raster, x$x, x$y, x$width, x$height, : Empty raster
Example 2
This seems to fix Example 1, but I don’t know if it is the best approach.
d <- data.frame(x = 1, y = 1, label = "{.p  }")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label))
Example 3
Can we modify Example 2 to make the logo larger by using the
width
argument?
d <- data.frame(x = 1, y = 1, label = "{.p  }")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label), width = unit(5, "cm"))
Nope, the logo is the same size, but now it is offset to the left
because the width
argument scaled the container size
instead of scaling the image size..
But wait, what if we use the clever trick that Teun shared
({.30 {.p ![]()}}
)?
d <- data.frame(x = 1, y = 1, label = "{.30 {.p  }}")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label))
Cool! The {.30 {.p ![]()}}
syntax works for scaling an
image.
Example 4
Surprisingly, it seems that when we provide a width
,
Example 1 works!
d <- data.frame(x = 1, y = 1, label = "")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label), width = unit(5, "cm"))
And we can scale it as large as we want:
d <- data.frame(x = 1, y = 1, label = "")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label), width = unit(25, "cm"))
We can scale the image to fit the width of the plot with
unit(1, "npc")
:
d <- data.frame(x = 1, y = 1, label = "")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label), width = unit(1, "npc"))
Example 5
I’m not sure what the number indicates in the
{.150 {.p ![]()}}
syntax, so let’s see if it is equivalent
to using width = unit(150, "points")
:
d <- data.frame(x = 1, y = 1, label = "{.150 {.p  }}")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label)) +
labs(title = '{.150 {.p ![]() }}')
d <- data.frame(x = 1, y = 1, label = "")
ggplot(d) + geom_marquee(aes(x = x, y = y, label = label), width = unit(150, "points")) +
labs(title = 'width = unit(150, "points")')
Created on 2025-09-02 with reprex v2.1.1
Session info
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.5.1 (2025-06-13)
#> os macOS Sequoia 15.5
#> system aarch64, darwin20
#> ui X11
#> language (EN)
#> collate en_US.UTF-8
#> ctype en_US.UTF-8
#> tz America/New_York
#> date 2025-09-02
#> pandoc 3.7.0.2 @ /Users/ks38/src/pandoc-3.7.0.2-arm64/bin/ (via rmarkdown)
#> quarto 1.7.32 @ /usr/local/bin/quarto
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> cli 3.6.5 2025-04-23 [1] CRAN (R 4.5.0)
#> curl 7.0.0 2025-08-19 [1] CRAN (R 4.5.0)
#> digest 0.6.37 2024-08-19 [1] CRAN (R 4.5.0)
#> dplyr 1.1.4 2023-11-17 [1] CRAN (R 4.5.0)
#> evaluate 1.0.4 2025-06-18 [1] CRAN (R 4.5.0)
#> farver 2.1.2 2024-05-13 [1] CRAN (R 4.5.0)
#> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.5.0)
#> fs 1.6.6 2025-04-12 [1] CRAN (R 4.5.0)
#> generics 0.1.4 2025-05-09 [1] CRAN (R 4.5.0)
#> ggplot2 * 3.5.2 2025-04-09 [1] CRAN (R 4.5.0)
#> glue 1.8.0 2024-09-30 [1] CRAN (R 4.5.0)
#> gtable 0.3.6 2024-10-25 [1] CRAN (R 4.5.0)
#> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.5.0)
#> knitr 1.50 2025-03-16 [1] CRAN (R 4.5.0)
#> labeling 0.4.3 2023-08-29 [1] CRAN (R 4.5.0)
#> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.5.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.5.0)
#> marquee * 1.1.0 2025-08-19 [1] CRAN (R 4.5.0)
#> pillar 1.11.0 2025-07-04 [1] CRAN (R 4.5.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.5.0)
#> R6 2.6.1 2025-02-15 [1] CRAN (R 4.5.0)
#> RColorBrewer 1.1-3 2022-04-03 [1] CRAN (R 4.5.0)
#> reprex 2.1.1 2024-07-06 [1] CRAN (R 4.5.0)
#> rlang 1.1.6 2025-04-11 [1] CRAN (R 4.5.0)
#> rmarkdown 2.29 2024-11-04 [1] CRAN (R 4.5.0)
#> rsvg 2.6.2 2025-03-23 [1] CRAN (R 4.5.0)
#> scales 1.4.0 2025-04-24 [1] CRAN (R 4.5.0)
#> sessioninfo 1.2.3 2025-02-05 [1] CRAN (R 4.5.0)
#> stringi 1.8.7 2025-03-27 [1] CRAN (R 4.5.0)
#> systemfonts 1.2.3 2025-04-30 [1] CRAN (R 4.5.0)
#> textshaping 1.0.1 2025-05-01 [1] CRAN (R 4.5.0)
#> tibble 3.3.0 2025-06-08 [1] CRAN (R 4.5.0)
#> tidyselect 1.2.1 2024-03-11 [1] CRAN (R 4.5.0)
#> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.5.0)
#> withr 3.0.2 2024-10-28 [1] CRAN (R 4.5.0)
#> xfun 0.53 2025-08-19 [1] CRAN (R 4.5.0)
#> xml2 1.4.0 2025-08-20 [1] CRAN (R 4.5.0)
#> yaml 2.3.10 2024-07-26 [1] CRAN (R 4.5.0)
#>
#> [1] /Library/Frameworks/R.framework/Versions/4.5-arm64/Resources/library
#> * ── Packages attached to the search path.
#>
#> ──────────────────────────────────────────────────────────────────────────────