jthomasmock / gtExtras

A Collection of Helper Functions for the gt Package.
https://jthomasmock.github.io/gtExtras/
Other
193 stars 26 forks source link

All negative values in gt_plt_bar() #97

Closed daneel6672 closed 1 year ago

daneel6672 commented 1 year ago

Description

gt_plt_bar() has missing bar plots when all the values in the bar plot are negative

Reproducible example

mtcars_test <- mtcars
mtcars_test[,"mpg"] <- -mtcars_test[,"mpg"]
mtcars_test %>%
  head() %>%
  gt() %>%
  gt_plt_bar(column = mpg, keep_column = TRUE)

Expected result

A bar plot with all negative values (zero on the right for all of them)

mpg example

jthomasmock commented 1 year ago

Howdy!

All the plots appear correct to me unless I'm missing something?

The bar charts have a vertical black line indicating zero, so left-facing bars are negative and right-facing are positive.

library(gtExtras)
#> Loading required package: gt

mtcars_test <- mtcars
mtcars_test[,"mpg"] <- -mtcars_test[,"mpg"]
mtcars_test %>%
  head() %>%
  dplyr::mutate(mpg = ifelse(mpg == -18.1, 18.1, mpg)) |> 
  gt() %>%
  gt_plt_bar(column = mpg, keep_column = TRUE) |> 
  gtExtras::gt_reprex_image()

Created on 2023-08-27 by the reprex package (v2.0.1)

jthomasmock commented 1 year ago

Closing for now, but let me know if I misunderstood the question.

daneel6672 commented 1 year ago

The picture I added was what the results are supposed to look like (I edited the actual picture). When I run the reproducible example I get blank graphs if all the bars have negative values.

image

jthomasmock commented 1 year ago

Hi @daneel6672 - this is what I'm seeing with the latest version of gtExtras:

library(gtExtras)

mtcars_test <- mtcars
mtcars_test[,"mpg"] <- -mtcars_test[,"mpg"]
mtcars_test %>%
  head() %>%
  gt() %>%
  gt_plt_bar(column = mpg, keep_column = TRUE)

image

daneel6672 commented 1 year ago

I had version gtExtras_0.4.5 which generates that blank output. I used your repository and upgraded to gtExtras_0.5.0 and now I see the same output as you. Thanks for your help and for making and maintaining such a great package.