Setting Decimal Accuracy in gtExtras Bar Plots

Greetings,

I am trying to change the accuracy of the numbers in gt_plt_bar scale_type = "number" to an accuracy of .01. The documentation states: "then the numbers in the plotted column will be added as a bar-label and formatted according to scales::label_percent() or scales::label_number()"

Where/how do I do this?

library(scales)
library(gt)
library(gtExtras)

gt_plt_bar_tab <- mtcars %>%
  head() %>%
  gt() %>%
  gt_plt_bar(column = wt, keep_column = TRUE, scale_type = "number")

Thanks

Hi @contrivedcorridors. You can do this by adding an argument for accuracy.

gt_plt_bar(column = wt, keep_column = TRUE, scale_type = "number", accuracy = 0.01)
1 Like

thanks @scottyd22 - I greatly appreciate it.

I looked at the source code

label = if (scale_type == "number") {
  scales::label_number(...)(.data$x)
} else if (scale_type == "percent") {
  scales::label_percent(...)(.data$x)
},

Thanks to your answer I interpreted that it passes the arguments provided after scale_type = "number" to scales::label_number. The ... is a placeholder for additional arguments passed to gt_plt_bar().

I'll definitely be able to apply that in the future.

1 Like

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.