gt-extras
  • Intro
  • API Reference
  1. Plotting
  2. gt_plt_dot
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_bar_pct
    • gt_plt_bar_stack
    • gt_plt_conf_int
    • gt_plt_dot
    • gt_plt_dumbbell
    • gt_plt_winloss
  • Colors
    • gt_color_box
    • gt_data_color_by_group
    • gt_highlight_cols
    • gt_highlight_rows
    • gt_hulk_col_numeric
  • Themes
    • gt_theme_538
    • gt_theme_dark
    • gt_theme_dot_matrix
    • gt_theme_espn
    • gt_theme_excel
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_pff
  • Icons and Images
    • add_text_img
    • fa_icon_repeat
    • gt_fa_rank_change
    • gt_fa_rating
    • img_header
  • Utilities
    • fmt_pct_extra
    • gt_add_divider
    • gt_duplicate_column
    • gt_merge_stack
    • gt_two_column_layout
    • with_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Examples
  • Note
  1. Plotting
  2. gt_plt_dot

gt_plt_dot

gt_plt_dot(gt, category_col, data_col, domain=None, palette=None)

Create dot plots with thin horizontal bars in GT cells.

The gt_plt_dot() function takes an existing GT object and adds dot plots with horizontal bar charts to a specified category column. Each cell displays a colored dot according to the value in the assigned category column and a horizontal bar representing the corresponding numeric value from the data column.

Parameters

gt : GT

A GT object to modify.

category_col : SelectExpr

The column containing category labels that will be displayed next to colored dots. The coloring of the dots are determined by this column.

data_col : SelectExpr

The column containing numeric values that will determine the length of the horizontal bars.

domain : list[int] | list[float] | None = None

The domain of values to use for the color scheme. This can be a list of floats or integers. If None, the domain is automatically set to [0, max(data_col)].

palette : list[str] | str | None = None

The color palette to use. This should be a list of colors (e.g., ["#FF0000", "#00FF00", "#0000FF"]). A ColorBrewer palette could also be used, just supply the name (see GT.data_color() for additional reference). If None, then a default palette will be used.

Returns

: GT

A GT object with dot plots and horizontal bars added to the specified category column.

Examples

from great_tables import GT
from great_tables.data import gtcars
import gt_extras as gte

gtcars_mini = gtcars.loc[8:20, ["model", "mfr", "hp", "trq", "mpg_c"]]

gt = (
    GT(gtcars_mini, rowname_col="model")
    .tab_stubhead(label="Car")
)

gt.pipe(gte.gt_plt_dot, category_col="mfr", data_col="hp")
Car mfr hp trq mpg_c
F12Berlinetta
Ferrari
731.0 509.0 11.0
LaFerrari
Ferrari
949.0 664.0 12.0
NSX
Acura
573.0 476.0 21.0
GT-R
Nissan
545.0 436.0 16.0
Aventador
Lamborghini
700.0 507.0 11.0
Huracan
Lamborghini
610.0 413.0 16.0
Gallardo
Lamborghini
550.0 398.0 12.0
Continental GT
Bentley
500.0 487.0 15.0
Granturismo
Maserati
454.0 384.0 13.0
Quattroporte
Maserati
404.0 406.0 16.0
Ghibli
Maserati
345.0 369.0 17.0
6-Series
BMW
315.0 330.0 20.0
i8
BMW
357.0 420.0 28.0

Note

If the column is too narrow, the bar may render above the dot rather than below, as intended. For the best way to resolve this issue please refer to GT.cols_width()

gt_plt_conf_int
gt_plt_dumbbell