gt-extras
  • Intro
  • API Reference
  1. Icons and Images
  2. gt_fa_rank_change
  • 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
  • Example
  1. Icons and Images
  2. gt_fa_rank_change

gt_fa_rank_change

gt_fa_rank_change(
    gt,
    column,
    neutral_range=[0],
    icon_type='angles',
    color_up='green',
    color_down='red',
    color_neutral='grey',
    show_text=True,
    font_color='black',
    size=12,
)

Create rank change indicators in GT cells using FontAwesome icons.

This function represents numeric rank changes in table column(s) by displaying FontAwesome icons alongside the numeric values. Values greater than the maximum of neutral_range show up-pointing icons (e.g., arrows up), values less than the minimum of the range show down-pointing icons (e.g., arrows down), and values within the neutral range show neutral indicators (equals sign).

Parameters

gt : GT

A GT object to modify.

column : SelectExpr

The column containing numeric rank change values.

neutral_range : list[int] | int = [0]

A single number or list of numbers defining the neutral range. If a single number, only that exact value is considered neutral. If a list of numbers, any value within that range (inclusive) is considered neutral.

icon_type : Literal['angles', 'arrow', 'turn', 'chevron', 'caret'] = 'angles'

The type of FontAwesome icon to use for indicating direction. Options include "angles", "arrow", "turn", "chevron", and "caret".

color_up : str = 'green'

The color for positive (upward) rank changes.

color_down : str = 'red'

The color for negative (downward) rank changes.

color_neutral : str = 'grey'

The color for neutral rank changes (values within the neutral range).

show_text : bool = True

Whether to display the numeric value alongside the icon.

font_color : str = 'black'

The color for the numeric text displayed alongside the icons.

size : int = 12

The size of the font as well as the icon. Specificially it is both the width of the icon in pixels and the font size of the text.

Returns

: GT

A GT object with rank change indicators added to the specified column.

Example

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

mini_towny = towny.head(10)
gt = GT(mini_towny).cols_hide(None).cols_unhide("name")

columns = [
    "pop_change_1996_2001_pct",
    "pop_change_2001_2006_pct",
    "pop_change_2006_2011_pct",
]

for col in columns:
    gt = (
        gt
        .cols_align(columns=col, align="center")
        .cols_unhide(col)
        .cols_label({col: col[11:20]})

        .pipe(
            gte.gt_fa_rank_change,
            column=col,
            neutral_range=[-0.01, 0.01],
        )
    )

gt
name 1996_2001 2001_2006 2006_2011
Addington Highlands
Angles down
-0.0111
Angles up
0.0458
Equals
0.002
Adelaide Metcalfe
Equals
0.0067
Equals
-0.0044
Angles down
-0.0341
Adjala-Tosorontio
Angles up
0.0773
Angles up
0.0608
Equals
-0.0086
Admaston/Bromley
Equals
-0.0046
Angles down
-0.0382
Angles up
0.0471
Ajax
Angles up
0.1447
Angles up
0.2226
Angles up
0.2155
Alberton
Angles down
-0.0691
Equals
0.0021
Angles down
-0.0981
Alfred and Plantagenet
Angles up
0.0334
Equals
0.0071
Angles up
0.0626
Algonquin Highlands
Angles up
0.083
Angles up
0.0816
Angles up
0.1063
Alnwick/Haldimand
Angles up
0.0575
Angles up
0.1008
Angles up
0.0283
Amaranth
Angles up
0.0928
Angles up
0.0199
Angles up
0.0307
fa_icon_repeat
gt_fa_rating