gt-extras
  • Intro
  • Examples
  • API Reference
  1. Plotting
  2. gt_plt_dot
  • API Reference
  • Plotting
    • gt_plt_bar
    • gt_plt_bar_pct
    • gt_plt_bar_stack
    • gt_plt_bullet
    • gt_plt_conf_int
    • gt_plt_dot
    • gt_plt_dumbbell
    • gt_plt_summary
    • 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,
    width=120,
    height=30,
    font_size=16,
    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.

width : int = 120

The width of the SVG plot in pixels. You may need to increase this if your category labels are long.

height : int = 30

The height of the SVG plot in pixels.

font_size : int = 16

The font size for the category label text.

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"]]

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
F12Berlinetta
Ferrari
731.0
LaFerrari
Ferrari
949.0
NSX
Acura
573.0
GT-R
Nissan
545.0
Aventador
Lamborghini
700.0
Huracan
Lamborghini
610.0
Gallardo
Lamborghini
550.0
Continental GT
Bentley
500.0
Granturismo
Maserati
454.0
Quattroporte
Maserati
404.0
Ghibli
Maserati
345.0
6-Series
BMW
315.0
i8
BMW
357.0

Note

If your category label text is cut off or does not fit, you likely need to increase the width parameter to allow more space for the text and plot.

gt_plt_conf_int
gt_plt_dumbbell