Closed engineerchange closed 2 years ago
Thanks for the reprex
!
So I've simplified and refactored the function internally, but given that I'm merging two columns and using gt::text_transform()
, the formatting is already applied. Thus any fmt()
functions converts the column to text and it is then passed forward with the formatting to the plotting function. Given that the formatted column could have any number of formats applied to it (ie, a "$", a "%", a "," or various other formats), I can't move forward with converting them back to a number. I've added an error if the column is converted to NA
, meaning it can't be used in ggplot2
.
I'll keep hacking away at it, but for now you could create a "duplicate" column on your own ahead of time, and then convert that to the plot. I may have to remove the keep_column
argument to push users down that route as a recommendation, but I'll see if I can do something more clever with the _data
. That approach is easier with raw data, but more brittle with regards to grouping of data or other transformations.
Adapting your code, a quick reprex
below works for me. Note that I have refactored gt_plt_bullet()
so I'd recommend installing the dev version again.
t1 %>%
dplyr::mutate(plot_column = max) %>%
gt() %>%
gt_plt_bullet(column=plot_column,target=med,
width=45,colors= c("lightblue","black"),keep_column = FALSE) %>%
gt::fmt_number(columns=c(max),decimals=0)
Got it! Thanks for clarifying; I thought I was going crazy. Appreciate all you do!!
Hey @engineerchange - I refactored the internals. Can you give this a try again with the latest release?
These are working as intended for me now.
# initial bullet plot
t1 %>%
gt() %>%
gt_plt_bullet(column = max, target = med, width = 45, keep_column = TRUE)
# same plot as above but we try to fmt_number() of keep column
t1 %>%
gt() %>%
gt_plt_bullet(column = max, target = med, width = 45, keep_column = TRUE) %>%
gt::fmt_number(columns = c(max), decimals = 0)
Not sure how I missed the parameters going from color="lightblue",target_color="black"
to colors=c("lightblue","black")
, but I think that's a nice change!
Confirmed the above works and no longer any weirdness with fmt_* functions. Appreciate the quick fix! Allons-y!
Can't reprex this nicely, so I'll add some commentary along the way.
Returns the following error:
These are double columns with no NA values, so a bit unclear on the error. Tried to reproduce with mtcars, but it worked fine.
Kind of peculiar.