wilkelab / ggtext

Improved text rendering support for ggplot2
https://wilkelab.org/ggtext/
GNU General Public License v2.0
655 stars 37 forks source link

Can't italicize ggplot label/titles after R update #89

Open XueWenSYan opened 2 years ago

XueWenSYan commented 2 years ago

Hi,

I was able to use ggtext as well as the mdthemes::md_theme_classic() options to control ggplot text formatting in the past. However, after an R update today, my codes run without error but the formatting will not be displayed in the plots.

For example, with this reproducible example, the plot I get is as the picture.

library(ggtext)
ggplot(mtcars, aes(hp, mpg)) +
+     geom_point() +
+     theme(plot.title = element_markdown()) +
+     labs(title = "**Bold Title**", x = "*Italics axis label*")

image

I'm running a Windows machine, and one possible issue is that my system locale is in Chinese (and I must keep it this way because I work with Chinese language data a lot). I already set my R default console language to English. When I try to change system locale during analysis, I keep seeing this warning using locale code page other than 65001 ("UTF-8") may cause problems. I didn't see this warning in the past.

Thank you!

> Sys.setlocale("LC_ALL","English")
[1] "LC_COLLATE=English_United States.1252;LC_CTYPE=English_United States.1252;LC_MONETARY=English_United States.1252;LC_NUMERIC=C;LC_TIME=English_United States.1252"
Warning message:
In Sys.setlocale("LC_ALL", "English") :
  using locale code page other than 65001 ("UTF-8") may cause problems

> Sys.setlocale("LC_ALL","Japanese")
[1] "LC_COLLATE=Japanese_Japan.932;LC_CTYPE=Japanese_Japan.932;LC_MONETARY=Japanese_Japan.932;LC_NUMERIC=C;LC_TIME=Japanese_Japan.932"
Warning message:
In Sys.setlocale("LC_ALL", "Japanese") :
  using locale code page other than 65001 ("UTF-8") may cause problems

> sessionInfo()
R version 4.2.0 (2022-04-22 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22000)

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] forcats_0.5.1   stringr_1.4.0   dplyr_1.0.9     purrr_0.3.4     readr_2.1.2     tidyr_1.2.0    
[7] tibble_3.1.7    ggplot2_3.3.6   tidyverse_1.3.1

loaded via a namespace (and not attached):
 [1] nlme_3.1-157         ggtext_0.1.1         fs_1.5.2             lubridate_1.8.0     
 [5] httr_1.4.3           tools_4.2.0          backports_1.4.1      utf8_1.2.2          
 [9] R6_2.5.1             rpart_4.1.16         mdthemes_0.1.0       DBI_1.1.2           
[13] colorspace_2.0-3     nnet_7.3-17          withr_2.5.0          tidyselect_1.1.2    
[17] compiler_4.2.0       cli_3.3.0            rvest_1.0.2          xml2_1.3.3          
[21] labeling_0.4.2       scales_1.2.0         digest_0.6.29        rmarkdown_2.14      
[25] pkgconfig_2.0.3      htmltools_0.5.2      parallelly_1.31.1    dbplyr_2.1.1        
[29] fastmap_1.1.0        rlang_1.0.2          readxl_1.4.0         rstudioapi_0.13     
[33] farver_2.1.0         generics_0.1.2       jsonlite_1.8.0       ModelMetrics_1.2.2.2
[37] magrittr_2.0.3       Matrix_1.4-1         Rcpp_1.0.8.3         munsell_0.5.0       
[41] fansi_1.0.3          lifecycle_1.0.1      stringi_1.7.6        pROC_1.18.0         
[45] yaml_2.3.5           MASS_7.3-56          plyr_1.8.7           recipes_0.2.0       
[49] grid_4.2.0           parallel_4.2.0       listenv_0.8.0        crayon_1.5.1        
[53] lattice_0.20-45      haven_2.5.0          splines_4.2.0        gridtext_0.1.4      
[57] hms_1.1.1            knitr_1.39           pillar_1.7.0         markdown_1.1        
[61] future.apply_1.9.0   reshape2_1.4.4       codetools_0.2-18     stats4_4.2.0        
[65] reprex_2.0.1         glue_1.6.2           evaluate_0.15        data.table_1.14.2   
[69] modelr_0.1.8         vctrs_0.4.1          tzdb_0.3.0           foreach_1.5.2       
[73] cellranger_1.1.0     gtable_0.3.0         future_1.26.1        assertthat_0.2.1    
[77] xfun_0.31            gower_1.0.0          prodlim_2019.11.13   broom_0.8.0         
[81] class_7.3-20         survival_3.3-1       timeDate_3043.102    iterators_1.0.14    
[85] hardhat_1.0.0        lava_1.6.10          globals_0.15.0       ellipsis_0.3.2      
[89] caret_6.0-92         ipred_0.9-12     
bwiernik commented 2 years ago

I am having the same issue on R 4.2.0 on macOS (ARM).

library(ggplot2)
library(ggtext)
ggplot(mtcars) + aes(x = cyl, y = am) + annotate("richtext", x = 6, y = .5, label = "*This is italic*<br>**This is bold**")

image

> 
R version 4.2.0 (2022-04-22) -- "Vigorous Calisthenics"
Copyright (C) 2022 The R Foundation for Statistical Computing
Platform: aarch64-apple-darwin20 (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

  Natural language support but running in an English locale

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(ggplot2)
> library(ggtext)
> ggplot(mtcars) + aes(x = cyl, y = am) + annotate("richtext", x = 6, y = .5, label = "*This is italic*")
> ggplot(mtcars) + aes(x = cyl, y = am) + annotate("richtext", x = 6, y = .5, label = "*This is italic*<br>**This is bold**")
> sessioninfo::session_info()
─ Session info ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 setting  value
 version  R version 4.2.0 (2022-04-22)
 os       macOS Monterey 12.4
 system   aarch64, darwin20
 ui       RStudio
 language (EN)
 collate  en_US.UTF-8
 ctype    en_US.UTF-8
 tz       America/New_York
 date     2022-06-06
 rstudio  2022.02.3+492 Prairie Trillium (desktop)
 pandoc   NA

─ Packages ─────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
 package     * version date (UTC) lib source
 assertthat    0.2.1   2019-03-21 [1] CRAN (R 4.2.0)
 cli           3.3.0   2022-04-25 [1] CRAN (R 4.2.0)
 colorspace    2.0-3   2022-02-21 [1] CRAN (R 4.2.0)
 crayon        1.5.1   2022-03-26 [1] CRAN (R 4.2.0)
 DBI           1.1.2   2021-12-20 [1] CRAN (R 4.2.0)
 digest        0.6.29  2021-12-01 [1] CRAN (R 4.2.0)
 dplyr         1.0.9   2022-04-28 [1] CRAN (R 4.2.0)
 ellipsis      0.3.2   2021-04-29 [1] CRAN (R 4.2.0)
 fansi         1.0.3   2022-03-24 [1] CRAN (R 4.2.0)
 farver        2.1.0   2021-02-28 [1] CRAN (R 4.2.0)
 generics      0.1.2   2022-01-31 [1] CRAN (R 4.2.0)
 ggplot2     * 3.3.6   2022-05-03 [1] CRAN (R 4.2.0)
 ggtext      * 0.1.1   2020-12-17 [1] CRAN (R 4.2.0)
 glue          1.6.2   2022-02-24 [1] CRAN (R 4.2.0)
 gridtext      0.1.4   2020-12-10 [1] CRAN (R 4.2.0)
 gtable        0.3.0   2019-03-25 [1] CRAN (R 4.2.0)
 labeling      0.4.2   2020-10-20 [1] CRAN (R 4.2.0)
 lifecycle     1.0.1   2021-09-24 [1] CRAN (R 4.2.0)
 magrittr      2.0.3   2022-03-30 [1] CRAN (R 4.2.0)
 markdown      1.1     2019-08-07 [1] CRAN (R 4.2.0)
 munsell       0.5.0   2018-06-12 [1] CRAN (R 4.2.0)
 pillar        1.7.0   2022-02-01 [1] CRAN (R 4.2.0)
 pkgconfig     2.0.3   2019-09-22 [1] CRAN (R 4.2.0)
 purrr         0.3.4   2020-04-17 [1] CRAN (R 4.2.0)
 R6            2.5.1   2021-08-19 [1] CRAN (R 4.2.0)
 ragg          1.2.2   2022-02-21 [1] CRAN (R 4.2.0)
 Rcpp          1.0.8.3 2022-03-17 [1] CRAN (R 4.2.0)
 rlang         1.0.2   2022-03-04 [1] CRAN (R 4.2.0)
 scales        1.2.0   2022-04-13 [1] CRAN (R 4.2.0)
 sessioninfo   1.2.2   2021-12-06 [1] CRAN (R 4.2.0)
 stringi       1.7.6   2021-11-29 [1] CRAN (R 4.2.0)
 stringr       1.4.0   2019-02-10 [1] CRAN (R 4.2.0)
 systemfonts   1.0.4   2022-02-11 [1] CRAN (R 4.2.0)
 textshaping   0.3.6   2021-10-13 [1] CRAN (R 4.2.0)
 tibble        3.1.7   2022-05-03 [1] CRAN (R 4.2.0)
 tidyselect    1.1.2   2022-02-21 [1] CRAN (R 4.2.0)
 utf8          1.2.2   2021-07-24 [1] CRAN (R 4.2.0)
 vctrs         0.4.1   2022-04-13 [1] CRAN (R 4.2.0)
 withr         2.5.0   2022-03-03 [1] CRAN (R 4.2.0)
 xml2          1.3.3   2021-11-30 [1] CRAN (R 4.2.0)

 [1] /Library/Frameworks/R.framework/Versions/4.2-arm64/Resources/library

────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────
clauswilke commented 2 years ago

Is this related to this issue? https://github.com/wilkelab/gridtext/issues/24

If yes, it's been fixed in the development version of gridtext and installing that should resolve your problems.

I'm aware I need to make a new release for CRAN. Will probably get to this this week.

bwiernik commented 2 years ago

Ah, yep, that fixes it. Thanks

clauswilke commented 2 years ago

Good to know, thanks! I'll leave this issue open until the fix is on CRAN.

XueWenSYan commented 2 years ago

Hi, the issue's solved now after installing remotes::install_github("wilkelab/gridtext"). Thanks!