# NOT RUN {
library(ggplot2)
# Create a ggplot plot
plot_object <-
ggplot(
data = gtcars,
aes(x = hp, y = trq,
size = msrp)) +
geom_point(color = "blue") +
theme(legend.position = "none")
# Create a tibble that contains two
# cells (where one is a placeholder for
# an image), then, create a gt table;
# use the `text_transform()` function
# to insert the plot using by calling
# `ggplot_object()` within the user-
# defined function
tab_1 <-
dplyr::tibble(
text = "Here is a ggplot:",
ggplot = NA
) %>%
gt() %>%
text_transform(
locations = cells_body(vars(ggplot)),
fn = function(x) {
plot_object %>%
ggplot_image(height = px(200))
}
)
# }
Run the code above in your browser using DataLab