I'm creating a poster for a conference which uses data about kidney function and potassium levels.
I've created a summary table of data from within a much larger dataset and am trying to use the gt() package to create my tables.
(I'm a doctor, without formal data science training, and this is my first time asking a question (I've always been able to google the answers until now), I've tried to make a reproducible example but please go easy on me if I've not provided enough information!)
I created this data set by grouping according to levels of kidney function (ckdlevel) and maximum potassium (Max K+)
I managed (eventually) to figure out how to convert >= into ≤ so that it formatted properly
I want to convert mls/min/1.73m2 into mls/min/1.73m 2, but I get the following error message.
One option I've figured out is to use a footnote, but my supervisor is not keen on this. Is there a way to fix this?
library(tidyverse)
library(gt)
data <- structure(list(
ckdlevel = c("<15 mls/min/1.73m^2", "<15 mls/min/1.73m^2",
"15-29 mls/min/1.73m^2", "15-29 mls/min/1.73m^2", "30 - 44 mls/min/1.73m^2",
"30 - 44 mls/min/1.73m^2", "45 - 59 mls/min/1.73m^2", "45 - 59 mls/min/1.73m^2",
">60 mls/min/1.73m^2", ">60 mls/min/1.73m^2", "Missing", "Missing"
),
`Max K+` = c(" ltoet5 mmol/l", ">5 mmol/l", " ltoet5 mmol/l",
">5 mmol/l", " ltoet5 mmol/l", ">5 mmol/l", " ltoet5 mmol/l",
">5 mmol/l", " ltoet5 mmol/l", ">5 mmol/l", " ltoet5 mmol/l",
">5 mmol/l"),
n = c(100, 200, 300, 400, 500, 600, 700, 800, 900, 800, 700, 600)),
row.names = c(NA, -12L),
class = c("tbl_df", "tbl", "data.frame"))
data %>%
group_by(ckdlevel) %>%
gt() %>%
text_transform(
locations = cells_body(
columns = "Max K+"),
fn = function(x) {
str_replace(x, pattern = "ltoet", replacement = "<span>≤</span>")
}
) %>%
text_transform(
locations = cells_row_groups(
groups = everything()),
fn = function(x) {
str_replace(x, pattern = "^2", replacement = "<sup>2</sup>")
}
)
#> Error in UseMethod("resolve_location"): no applicable method for 'resolve_location' applied to an object of class "c('cells_row_groups', 'location_cells')"
Thank you!