davidgohel / flextable

table farming
https://ardata-fr.github.io/flextable-book/
554 stars 79 forks source link

Hebrew ggplot2 axis labels are removed when flextable is loaded #542

Open matanhakim opened 1 year ago

matanhakim commented 1 year ago

Let's imagine I want to create a simple plot with ggplot:

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.2.3

mtcars |> 
  ggplot(aes(factor(cyl))) +
  geom_bar() 

Created on 2023-05-18 with reprex v2.0.2

This is great. Now, let's assume I would like to change the X axis labels to Hebrew. (The letters are equivalent to "A, B, C")

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.2.3

mtcars |> 
  ggplot(aes(factor(cyl))) +
  geom_bar() +
  scale_x_discrete(labels = c("א", "ב", "ג"))

Created on 2023-05-18 with reprex v2.0.2

Again, This works perfectly.

On our third step, let's go back to English labels, but now load flextable.

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.2.3
library(flextable)
#> Warning: package 'flextable' was built under R version 4.2.3

mtcars |> 
  ggplot(aes(factor(cyl))) +
  geom_bar()

Created on 2023-05-18 with reprex v2.0.2

Now comes the problem. When I both load flextable and use Hebrew labels, the labels dissappear:

library(ggplot2)
#> Warning: package 'ggplot2' was built under R version 4.2.3
library(flextable)
#> Warning: package 'flextable' was built under R version 4.2.3

mtcars |> 
  ggplot(aes(factor(cyl))) +
  geom_bar() +
  scale_x_discrete(labels = c("א", "ב", "ג"))

Created on 2023-05-18 with reprex v2.0.2

I have no idea what causes this, but since this is such a sneaky bug it took me about two hours to locate. I feel this should be addressed. Thanks for the package and the work around it!

> sessionInfo()
R version 4.2.1 (2022-06-23 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 19045)

Matrix products: default

locale:
[1] LC_COLLATE=English_United States.utf8  LC_CTYPE=English_United States.utf8   
[3] LC_MONETARY=English_United States.utf8 LC_NUMERIC=C                          
[5] LC_TIME=English_United States.utf8    

attached base packages:
[1] stats     graphics  grDevices utils     datasets  methods   base     

other attached packages:
[1] flextable_0.9.1 ggplot2_3.4.2   reprex_2.0.2