Questions tagged [gt]

Use this tag for questions related to the gt package. The gt package provides functions to make it easy to create and style tables in the R programming language.

The package provides functions to make it easy to create and style tables in the programming language. Like the grammar of graphics for data visualization (see ), the philosophy behind is to provide a grammar of tables.

An overview and introduction to the package can be found on the package website.

429 questions
6
votes
2 answers

How should I format across rows of a gt table efficiently in R?

If I want to efficiently format rows of a gt table, is there a better method than what I have shown below. Some rows are character, and so need no formatting, some are numbers where one decimal place is required, some are numbers where two decimal…
Mark Neal
  • 996
  • 16
  • 52
5
votes
1 answer

R gt add vertical lines between spanner columns throughout table

I want to add a thicker (px(2)) vertical line between each of the spanner columns that runs throughout the figure. I have looked through the tab_options and have not found a combination that allows for the line to go through all of the table at the…
melmo
  • 757
  • 3
  • 15
5
votes
1 answer

Adding a footnote to a single row label in a gtsummary table

I'm trying to add a footnote to a row label of a gtsummary table, but I can't figure out how to reference the exact cell I want. Intended output Usint the default trial dataset, I'd like to add a footnote to "Drug B" that reads "i.e.…
Andrea M
  • 2,314
  • 1
  • 9
  • 27
5
votes
1 answer

Combine multiple gt tables to single one plot

With code below (edited basing on code from here) I generates two example tables with gt package: library(tidyverse) library(patchwork) library(gt) p1 <- mtcars %>% head(5) %>% gt() p2 <- mtcars %>% tail(5) %>% gt() # using wrap…
ah bon
  • 9,293
  • 12
  • 65
  • 148
5
votes
3 answers

Using a For-loop to create multiple tables

I'm trying to figure out if there's a way to use for-loops to create multiple tables in one go, all using the same dataset - I'll clarify that in a second. I'm using R Markdown, because I need to compile it in a PDF in the end, if that makes any…
Abigail C.
  • 53
  • 3
5
votes
3 answers

Special zero value in gt tables

I'm using the {gt} package to create tables in a report. I would like it so that the "$0.00" currency values are replaced with "-", which is something that's easy to do in Excel but seems surprisingly hard to do with {gt}. Here is an example of a…
Jacqueline Nolis
  • 1,457
  • 15
  • 22
5
votes
0 answers

Repeat the column label on row group line in gt

I am building a long table using gt, and I would like to know if there is a way to repeat the column labels on row group line. On the image of gt table, repeat the "COLUMN LABEL" on the hatched parts of "ROW GROUP LABEL" line. Thanks for your…
akyves
  • 201
  • 1
  • 6
5
votes
2 answers

Grouping Rows in GTSummary

I am trying to group some rows/variables (both categorical and continuous) to help with the table readability in a large dataset. Here is the dummy dataset: library(gtsummary) library(tidyverse) library(gt) set.seed(11012021) # Create Dataset PIR…
Benjamin Moran
  • 109
  • 1
  • 8
5
votes
2 answers

Is there a clever way to get two column spanner labels in an R GT table?

The code below library(magrittr) library(gt) library(dplyr) TestColumn_one <- c("CA", "FL", "GA", "MA", "NM", "OH", "OK", "TN", "UT") TestColumn_two <- c(1, 2, 3, 4, 5, 6, 7, 8, 9) TestColumn_three <- c(1, 2, 3, 4, 5, 6, 7, 8, 9) TestColumn_four <-…
jerH
  • 1,085
  • 1
  • 12
  • 30
5
votes
2 answers

Is it possible to use sparkline with gt?

I would like to use sparkline mini charts with gt's package table. Is it possible? I know it is possible with formattable, but I would prefer to use gt tables. Here is what I want to accomplish and how to do it with…
Jakub.Novotny
  • 2,912
  • 2
  • 6
  • 21
5
votes
1 answer

Set asymmetric midpoint for data_color in gt table

I am trying to recreate a simple table from 538 using the gt package. I want to use 0 as the midpoint of the domain of the color scale and set that to white but 0 is not the midpoint of the actual domain. df <- tribble( ~SEASON, ~ACC, ~BIG_10,…
5
votes
1 answer

Right align the rowname_col in gt

I'd like to right align the rowname_col but it doesn't look like you can apply cols_align to rownames? tibble( one = c("Long names", "Other Name", "Name | Name"), two = 1:3 ) %>% gt(rowname_col = "one") %>% cols_align(align = "right", columns…
MayaGans
  • 1,815
  • 9
  • 30
4
votes
2 answers

gt() table - header color

How do I add color to the header (i.e the column names) of my data frame using the gt() function in R gt_Head <- gt_Head %>% tab_header( title = md("**Table of First 10 Observations**") )%>% tab_style( style = cell_text(weight =…
highclef
  • 169
  • 7
4
votes
1 answer

Wrapped text in tables when knitting to pdf using gt

Sorry if this is a very trivial question but I've looked up and down the internet and can't find an answer. I'm making a basic table using the gt package in markdown. But I can't seem to get the text to wrap when knitting to a *.pdf. Any help would…
randmlaber
  • 109
  • 1
  • 1
  • 6
4
votes
2 answers

R ggplot and gt outputs - how can I combine these on an output image

In base R I have some code that writes a table of statistics below a chart. I would like to do a similar process with a 'ggplot' chart and a 'gt' table. What is the best way to go about this? My attempt below using gridExtra failed. # load…
Markm0705
  • 1,340
  • 1
  • 13
  • 31
1
2
3
28 29