jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
195 stars 27 forks source link

Function to embed ggplots in gt #35

Closed lbenz730 closed 2 years ago

lbenz730 commented 2 years ago

Hi Tom,

Thanks for all your hard work on the gtExtras package. I am wondering if it would be fairly straightforward to add a function that makes a column of user supplied charts a column in the table w/in a gt. I have done an example of this here, by saving image files out (via ggsave) and then manually loading them in and using text_transform to create a column with the graphs as cells.

The motivation behind such a function would be allow give a lot of flexibility to the user, and not all charts would need to be the same type, nor would the gtExtras package be responsible for the creation of the chart(s) in question.

I am not exactly certain how this would work in your API but I imagine something like the following steps:

Some challenges I would anticipate:

I don't know what kind of effort this would require, and its definitely an enhancement request, not a bug. Thanks for all your efforts!

--Luke

jthomasmock commented 2 years ago

Howdy! This is already largely possible via gt::ggplot_image()

https://gt.rstudio.com/reference/ggplot_image.html

It uses text_transform() + ggplot_image() to embed user-defined plots.

lbenz730 commented 2 years ago

Oh thanks for point this out. I agree the functionality requested would likely be mostly redundant