Is there a way to color the Sparkline in gtExtras?

44 Views Asked by At

I am working on a gtExtras table with the following example

library(gt)
library(gtExtras)
library(dplyr)

dd <- data.frame(
  where = c("where1", "where2", "where3", "where4"),
  "year_2014" = c(30, 60, 20, 10),
  "year_2022" = c(10, 50, 30, 20)) 

dd |> rowwise() |>
  mutate(change = list(c(year_2014, year_2022))) |>
  gt() |>
  gt_plt_sparkline(change, label = FALSE)

enter image description here

I intend to color the Sparkline (the full Sparkline and not the end, as it in the default) depending on whether there was a decrease "green" or an increase "red".

How do I proceed?

1

There are 1 best solutions below

0
rdelrossi On

Consider doing plots in gt directly. Starting in version 0.10.0, sparkline and bar charts can be embedded directly with cols_nanoplot(). You can control colors with nanoplot_options().