I'm having trouble formatting my final GT table. The left one in the image was what my code was outputting on Jan 9th. I went away for a week and ran the exact same code, now it's outputting the one on the right.
I was unable to replicate the issue using just generic iris data. I just want the table to output the same as it did before.
Since I can't make an easy to reproduce example, I'll just dump my entire table here - also because I don't know where the issue is.
If anyone has any idea on how to fix the sizing of the saved GT table I would greatly appreciate it.
The data is stored here, the code doesn't read from the google drive.
library(tidyverse)
library(gt)
library(gtExtras)
library(here)
library(lubridate)
library(janitor)
ramp <- readxl::read_xlsx(file.path(paste0(here(),"/Raw data"),"Ramp data.xlsx"))
tidy_ramp <- ramp %>%
clean_names() %>%
as_tibble() %>%
mutate(date = ymd(date),
unique_pilly_key = paste(date, bnav, ship_4)) %>%
filter(type_5 != "Osprey non-ramp") %>%
mutate(type_5 = fct_relevel(type_5, "Wissa", "Tichka", "Osprey", "Horse Head", "Regular pilly", "SL"),
ship_4 = fct_relevel(ship_4, "Sloop", "Bagh", "WF","GF", "WG"),
dnav = fct_relevel(dnav, "-","Booched","Poor","Fine","Good","Exc","Merc"))
leaderboard <- tidy_ramp %>%
arrange(desc(poe_per_pirate)) %>%
select(date, bnaver, type_5, type_8, ship_4, ship_11, pirates, enemy_pirates, poe, poe_per_pirate, kb, expo) %>%
mutate(rank = row_number()) %>%
relocate(rank, .before = date) %>%
head(30) %>%
mutate(
expo = replace(expo, is.na(expo), ""),
player_url = case_when(
ship_4 == "Sloop" ~ ".png",
ship_4 == "Fanch" ~ ".png",
ship_4 == "Bagh" ~ ".png",
ship_4 == "WF" ~ ".png"
),
enemy_url = case_when(
ship_11 == "Sloop" ~ ".png",
ship_11 == "Cutter" ~ ".png",
ship_11 == "Dhow" ~ ".png",
ship_11 == "Fanch" ~ ".png",
ship_11 == "LS" ~ ".png",
ship_11 == "Bagh" ~ ".png",
ship_11 == "Junk" ~ ".png",
ship_11 == "WB" ~ ".png",
ship_11 == "MB" ~ ".png",
ship_11 == "MG" ~ ".png",
ship_11 == "Xebec" ~ ".png",
ship_11 == "WF" ~ ".png",
ship_11 == "GF" ~ ".png",
),
kb_url = case_when(
kb == "" ~ ".png",
kb == "x" ~ ".png"
),
type_8 = case_when(
type_8 == "Brig" ~ ".png",
type_8 == "Barb" ~ ".png"
),
vs = "vs",
enemy_pirates = ifelse(is.na(enemy_pirates), "?", enemy_pirates),
poe_per_enemy = round(poe/enemy_pirates,0)) %>%
relocate(player_url, .before = ship_4) %>%
relocate(enemy_url, .before = ship_11) %>%
relocate(vs, .before = enemy_url) %>%
select(-ship_4, -ship_11) %>%
relocate(pirates, .before = player_url) %>%
relocate(kb_url, .before = expo) %>%
relocate(poe_per_enemy, .before = kb) %>%
select(-kb) %>%
gt() %>%
gt_img_rows(columns = player_url, height = 25) %>%
gt_img_rows(columns = enemy_url, height = 25) %>%
gt_img_rows(columns = kb_url, height = 25) %>%
gt_img_rows(columns = type_8, height = 25) %>%
fmt_number(
columns = c(poe, poe_per_pirate, poe_per_enemy),
decimals = 0
) %>%
tab_style(
style = cell_borders(
sides = c("left"),
color = "black",
weight = px(1.5),
style = "solid"
),
locations = cells_body(
columns = c(poe, pirates, date)
)
) %>%
cols_align(
align = "left",
columns = c(type_5)
) %>%
cols_align(
align = "center",
columns = c(player_url, enemy_url, pirates, type_8, enemy_pirates, kb_url, vs)
) %>%
# data_color(columns = poe_per_pirate) %>%
cols_label(
player_url = "Player",
type_5 = "Route",
type_8 = "Fray",
enemy_url = "Enemy",
poe_per_pirate = "Poe/pirate",
poe_per_enemy = "Poe/enemy",
enemy_pirates = "Enemies",
vs = " ",
kb_url = "KB?",
expo = "Comment"
) %>%
tab_header(
title = md("Pillage Battle Leaderboard"),
subtitle = md("Data by Aquaneer as of 2025-01-17")
) %>%
gt_theme_538() %>%
tab_options(heading.title.font.size = "24px") %>%
opt_align_table_header(align = "center")
leaderboard
gtsave(leaderboard,
"Pillage Leaderboard 2025 01 17 V2.png",
file.path(paste0(here(),"/Output")))