Skip to content

Instantly share code, notes, and snippets.

@jthomasmock
Last active March 11, 2021 09:53
Show Gist options
  • Save jthomasmock/67892387f23708b94819ef12ee76dc70 to your computer and use it in GitHub Desktop.
Save jthomasmock/67892387f23708b94819ef12ee76dc70 to your computer and use it in GitHub Desktop.
``` 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