Xuewen
Xuewen

Reputation: 11

Can't italicize ggplot label/titles & ggtext not working after R update

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, I get a plot, but the texts aren't italicized or bolded.

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

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 the system locale during analysis, I keep seeing this warning `using a 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     

Upvotes: 0

Views: 676

Answers (1)

TarJae
TarJae

Reputation: 79244

Use theme(axis.title.x = element_text(face = "italic")):

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

enter image description here

Upvotes: 1

Related Questions