Converting a reactable to ggplot (or similar)

I've currently got a reactable stored as an object in some code. I'd like to be able to convert said object into a ggplot, but no matter what I do, I get variations of the same error. The reactable is derived from a pretty simple dataframe as set up below:

df <- structure(list(Date = c("2019-02-09", "2019-02-09", "2019-02-09", 
"2019-02-09", "2019-02-09", "2019-02-09", "2020-02-09", "2020-02-09", 
"2020-02-09", "2020-02-09", "2021-02-09", "2021-02-09", "2021-02-09", 
"2021-02-09"), Type = c("HUF", "HAD", "WOK", "STR", "HUF", "HAD", 
"WOK", "STR", "HUF", "HAD", "WOK", "STR", "HUF", "HAD"), Value = c(12L, 
226394L, 27566L, 217098L, 208463L, 9320L, 156607L, 19790L, 24541L, 
1074419L, 17250L, 12249L, 43651L, 45121L)), class = "data.frame", row.names = c(NA, 
-14L))

react_df <- reactable(df, highlight =  TRUE, compact = TRUE,pagination = FALSE)

react_df

Is this possible?

EDIT: Here's the reactable that I'm looking to convert:

react_df <- reactable(df, highlight = TRUE, compact = TRUE,pagination = FALSE, columns = list(Date = colDef(name = "Last Recorded", align = 'center'), Type = colDef(name = "Category", align = 'center'), Value = colDef(name = "Change(s)", align = 'center', cell = data_bars(df, background = "white", border_width = "2px", bar_height = 3, align_bars = "left", text_position = "outside-end", max_value = 1, number_fmt = scales::percent))))

react_df

One way to add a table to a ggplot is with the ggpmisc package. The code below adds the table to a plot at (0, 0).

Note - the lines starting with "theme" are not necessary but added for formatting purposes.

library(ggpmisc)

ggplot() +
  annotate(geom = "table", x = 0, y = 0, label = list(df)) +
  # below removes all plot labels, gridlines (not necessary)
  theme_minimal() +
  theme(panel.grid = element_blank(),
        axis.text = element_blank(),
        axis.title = element_blank()
        )

image

Created on 2022-09-26 with reprex v2.0.2.9000

1 Like

Thanks a lot for looking into it, it's not quite what I'm after. There's some small changes done in the reactable I'm looking for (updated OP)

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.