Skip to content

Instantly share code, notes, and snippets.

@jthomasmock
Last active Mar 11, 2021
Embed
What would you like to do?
``` r
library(ggplot2)
library(dplyr)
library(magick)
library(patchwork)
library(gt)
library(ggtext)
mtcars %>%
head() %>%
gt() %>%
gtsave("mtcars-tab.png")
```
``` r
table_img <- magick::image_read("mtcars-tab.png") %>%
image_ggplot(interpolate = TRUE)
basic_plot <- ggplot(mtcars, aes(x = cyl, y = mpg)) +
geom_jitter()
table_url <- "https://themockup.blog/posts/2020-10-31-embedding-custom-features-in-gt-tables/preview.png"
table_img2 <- ggplot() +
ggtext::geom_richtext(
aes(x =1, y =1, label = glue::glue("<img src='{table_url}' width='250'/>")),
size = 1,
fill = NA,
label.color = NA,
# remove background and outline
label.padding = grid::unit(rep(0, 4), "pt") # remove padding
) +
theme_void()
table_img2
```
``` r
basic_plot + table_img + basic_plot + table_img2 +
plot_layout(ncol = 2, widths = c(1, 2))
```
<sup>Created on 2021-01-27 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>
@jthomasmock
Copy link
Author

jthomasmock commented Jan 27, 2021

output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment