latex2exp icon indicating copy to clipboard operation
latex2exp copied to clipboard

Rendering mathematical operators and symbols in ggplot and plot

Open Gitmoid opened this issue 1 year ago • 3 comments

I seem to be having troubles displaying mathematical operators and other symbols while using ggplot() and plot() in RStudio. I reinstalled and deleted all R and RStudio folders. I tried opening the graphs in maximized new window. I haven't changed much in settings, only Appearance to Vibrant Ink and Sweave PDF Preview after compile using to RStudio Viewer. Otherwise, all of my RStudios settings should be set to default. Unicode characters work correctly.

> sessionInfo()
R version 4.2.2 (2022-10-31 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 22621) # Incorrect, Windows 11 Home, 22H2, build 22621.1344

Matrix products: default

locale:
[1] LC_COLLATE=Czech_Czechia.utf8  LC_CTYPE=Czech_Czechia.utf8    LC_MONETARY=Czech_Czechia.utf8 LC_NUMERIC=C                   LC_TIME=Czech_Czechia.utf8    

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

other attached packages:
[1] ggplot2_3.4.1   latex2exp_0.9.6

loaded via a namespace (and not attached):
 [1] zip_2.2.2        Rcpp_1.0.10      compiler_4.2.2   pillar_1.8.1     tools_4.2.2      digest_0.6.31    evaluate_0.20    lifecycle_1.0.3  tibble_3.2.0    
[10] gtable_0.3.1     pkgconfig_2.0.3  rlang_1.0.6      openxlsx_4.2.5.2 cli_3.6.0        rstudioapi_0.14  yaml_2.3.7       xfun_0.37        fastmap_1.1.1   
[19] withr_2.5.0      stringr_1.5.0    dplyr_1.1.0      knitr_1.42       generics_0.1.3   vctrs_0.5.2      grid_4.2.2       tidyselect_1.2.0 glue_1.6.2      
[28] R6_2.5.1         fansi_1.0.4      rmarkdown_2.20   farver_2.1.1     magrittr_2.0.3   scales_1.2.1     htmltools_0.5.4  colorspace_2.1-0 labeling_0.4.2  
[37] utf8_1.2.3       stringi_1.7.12   munsell_0.5.0   
library(latex2exp)
library(ggplot2)

ggplot(mtcars, aes(x = wt, y = mpg)) +
  geom_point() +
  xlab(TeX(r"($\alpha \cdot \beta$)")) + # incorrect for \cdot, works for alpha and beta
  ylab(TeX(r"($\pm \neg \subset$)")) + # incorrect
  labs(title = "\u03b1 \u2022 \u03b2") # correct

plot(TeX(r"($\alpha \cdot \beta$)")) # \cdot wrong again

image image

Gitmoid avatar Mar 08 '23 19:03 Gitmoid