gt
tableThe gt_plt_bar
function takes an existing gt_tbl
object and
adds horizontal barplots via ggplot2
. Note that values are plotted on a
shared x-axis, and a vertical black bar is added at x = zero. To add labels
to each of the of the bars, set scale_type
to either 'percent'
or 'number
'.
gt_plt_bar(
gt_object,
column = NULL,
color = "purple",
...,
keep_column = FALSE,
width = 40,
scale_type = "none",
text_color = "white"
)
An object of class gt_tbl
.
An existing gt table object of class gt_tbl
A single column wherein the bar plot should replace existing data.
A character representing the color for the bar, defaults to purple. Accepts a named color (eg 'purple'
) or a hex color.
Additional arguments passed to scales::label_number()
or scales::label_percent()
, depending on what was specified in scale_type
TRUE
/FALSE
logical indicating if you want to keep a copy of the "plotted" column as raw values next to the plot itself..
An integer indicating the width of the plot in pixels.
A string indicating additional text formatting and the addition of numeric labels to the plotted bars if not 'none'
. If 'none'
, no numbers will be added to the bar, but if "number"
or "percent"
are used, then the numbers in the plotted column will be added as a bar-label and formatted according to scales::label_percent()
or scales::label_number()
.
A string indicating the color of text if scale_type
is used. Defaults to "white"
library(gt)
gt_plt_bar_tab <- mtcars %>%
head() %>%
gt() %>%
gt_plt_bar(column = mpg, keep_column = TRUE)
3-4
Other Plotting:
gt_plt_bar_pct()
,
gt_plt_bar_stack()
,
gt_plt_dist()
,
gt_plt_percentile()
,
gt_plt_point()
,
gt_plt_sparkline()
,
gt_plt_winloss()