gt-extras
  • Get Started
  • API Reference
  1. Plotting
  2. gt_plt_dot
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_dot
  • Colors
    • gt_highlight_cols
    • gt_hulk_col_numeric
    • gt_color_box
  • Themes
    • gt_theme_538
    • gt_theme_espn
    • gt_theme_guardian
    • gt_theme_nytimes
    • gt_theme_excel
    • gt_theme_dot_matrix
    • gt_theme_dark
    • gt_theme_pff
  • Icons and Images
    • fa_icon_repeat
    • gt_fa_rating
  • HTML Helpers
    • gt_hyperlink
    • with_tooltip

On this page

  • Parameters
  • Returns
  • Examples
  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 with the category label 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.

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, style, loc
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")
)

gte.gt_plt_dot(gt, 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
gt_plt_bar
gt_highlight_cols