Closed jakelawlor closed 2 years ago
Fixed in v 0.2.4 - thanks for raising!
library(tibble)
library(gt)
library(gtExtras)
library(dplyr)
# make dataframe of individuals and their goals
df <- tribble(
~name, ~group, ~score, ~goal,
"Bob", "C", 20, 40,
"Chris", "A", 50, 40,
"Dale", "B", 30, 50,
"Jay", "A", 0, 40,
"Ben", "B", 10, 20
) %>%
# calculate percent towards goal, and cap at 100%
mutate(percent_to_goal = score/goal *100,
percent_to_goal = case_when(percent_to_goal >= 100 ~ 100,
TRUE ~ percent_to_goal))
df %>%
# make gt table
gt(rowname_col = "name", groupname_col = "group") %>%
# order groups
row_group_order(groups = c("A","B","C")) %>%
# add bar chart column
gt_plt_bar_pct(column = percent_to_goal) %>%
# highlight blue if person reaches their goal
tab_style(
style = list(
cell_fill(color = "lightcyan"),
cell_text(weight = "bold")),
locations = cells_body(
columns = c(goal,score, percent_to_goal),
rows = score >= goal
)
)
Hello,
I'm not totally sure if this is a bug or if it's user error, but I am noticing that columns in my table that are made with {gtExtras} are out of order when I rearrange my {gt} table by using groups.
I have a stackoverflow post about this here: https://stackoverflow.com/questions/71313688/gtextras-column-showing-in-wrong-order-in-gt-table-when-grouped but I will repeat the reprex below.
I am making a gt table showing the progress of individuals towards their goals. In the table, there is a row showing a horizontal bar graph of progress towards that goal (if goal is 50 and score is 40, the bar is at 80%).
However, when I change the order of the gt rows by using the
groupname_col
argument, the order of the other columns changes, as well as the order of thetab_style
formatting, but the order of thegtExtras::gt_plt_bar_pct()
column does not. It appears thegtExtras::gt_plt_bar_pct
always appears in the same order of input data, rather than the order that is set insidegt()
function. This means that when I rearrange my table by group, the bar chart column ends up showing the wrong bar to go with the score and name in that row.I can fix this by using
arrange()
on the input data before thegt()
begins, but this doesn't seem like a permanent solution since I'm going to want to change the order of the rows to view by different groups. Like I said, I am not positive this is a bug, but I expected the columns made withgtExtras
would behave in the same way as columns made ingt
.Thanks for your advice, and I love the package overall!
In the image, the first row is Chris, who met their goal (so the row is blue), but the bar chart is showing the score of Bob (50% towards goal), the first row in the input dataframe.