View source: R/gt_plt_sparkline.R
gt_plt_sparkline | R Documentation |
gt
tableThe gt_plt_sparkline
function takes an existing gt_tbl
object and
adds sparklines via the ggplot2
. Note that if you'd rather plot summary
distributions (ie density/histograms) you can instead use: gtExtras::gt_plt_dist()
gt_plt_sparkline(
gt_object,
column,
type = "default",
fig_dim = c(5, 30),
palette = c("black", "black", "purple", "green", "lightgrey"),
same_limit = TRUE,
label = TRUE
)
gt_object |
An existing gt table object of class |
column |
The column wherein the sparkline plot should replace existing data. Note that the data must be represented as a list of numeric values ahead of time. |
type |
A string indicating the type of plot to generate, accepts |
fig_dim |
A vector of two numbers indicating the height/width of the plot in mm at a DPI of 25.4, defaults to |
palette |
A character string with 5 elements indicating the colors of various components. Order matters, and palette = sparkline color, final value color, range color low, range color high, and 'type' color (eg shading or reference lines). To show a plot with no points (only the line itself), use: |
same_limit |
A logical indicating that the plots will use the same axis range ( |
label |
A logical indicating whether the sparkline will have a numeric label for the last value in the vector, placed at the end of the plot. |
An object of class gt_tbl
.
library(gt) gt_sparkline_tab <- mtcars %>% dplyr::group_by(cyl) %>% # must end up with list of data for each row in the input dataframe dplyr::summarize(mpg_data = list(mpg), .groups = "drop") %>% gt() %>% gt_plt_sparkline(mpg_data)
1-4
Other Plotting:
gt_plt_bar_pct()
,
gt_plt_bar_stack()
,
gt_plt_bar()
,
gt_plt_dist()
,
gt_plt_percentile()
,
gt_plt_point()
,
gt_plt_winloss()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.