ggplot 和 Latex2exp 不显示正确的符号

问题描述 投票:0回答:1

我尝试在 ggplot 标题中使用 $\partial$ 但不幸的是它没有正确渲染。事实上,当我尝试这个例子时(https://uliniemann.com/blog/2022-02-21-math-annotations-in-ggplot2-with-latex2exp/),很多符号都是错误的。这可能是什么原因?

编辑:它不仅仅影响 ggpplot

plot(TeX(r'(A $\LaTeX$ test for $\partial$)'), cex=2, main="")

我还发现建议安装新字体(R 和 RStudio 不显示希腊字母和其他符号 - 显示方块),但这不起作用。另请参阅此处:https://github.com/stefano-meschiari/latex2exp/issues/61

旧帖子

# Copied example from link
library(ggplot2)
library(dplyr, warn.conflicts = FALSE)

df <- tibble(x = rep(1:3, times = 3), y = rep(1:3, each = 3)) %>%
  mutate(z = c(
    r"($\alpha \beta \gamma$)", 
    r"($\Alpha \Beta \Gamma$)", 
    r"($\chi \psi \omega$)",
    r"($x^n + y^n = z^n$)",
    r"($\int_0^1 x^2 + y^2 \ dx$)",
    r"($\sum_{i=1}^{\infty} \, \frac{1}{n^s} = \prod_{p} \frac{1}{1 - p^{-s}}$)",
    r"($\left[ \frac{N} { \left( \frac{L}{p} \right) - (m+n) } \right]$)",
    r"($S = \{z \in \bf{C}\, |\, |z|<1 \} \, \textrm{and} \, S_2=\partial{S}$)",
    r"($\frac{1+\frac{a}{b}}{1+\frac{1}{1+\frac{1}{a}}}$)"
  ))

ggplot(df) +
  geom_text(
    aes(
      x = x, y = y, 
      label = TeX(z, output = "character")
    ), 
    parse = TRUE,
    size = 12/.pt
  ) +
  scale_x_continuous(expand = c(0.25, 0)) +
  scale_y_reverse(expand = c(0.25, 0))

预期结果:

我的结果:

我的信息:

> sessionInfo()
R version 4.2.2 (2022-10-31 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 Kingdom.utf8  LC_CTYPE=English_United Kingdom.utf8   
[3] LC_MONETARY=English_United Kingdom.utf8 LC_NUMERIC=C                           
[5] LC_TIME=English_United Kingdom.utf8    

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

other attached packages:
[1] dplyr_1.1.3     latex2exp_0.9.6 cowplot_1.1.1   ggplot2_3.5.0  

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.11        pillar_1.9.0       compiler_4.2.2     RColorBrewer_1.1-3
 [5] R.methodsS3_1.8.2  viridis_0.6.4      R.utils_2.12.2     base64enc_0.1-3   
 [9] bitops_1.0-7       tools_4.2.2        ciftiTools_0.12.2  digest_0.6.33     
[13] evaluate_0.22      lifecycle_1.0.3    tibble_3.2.1       gtable_0.3.4      
[17] viridisLite_0.4.2  pkgconfig_2.0.3    rlang_1.1.1        RNifti_1.5.0      
[21] cli_3.6.1          oro.nifti_0.11.4   rstudioapi_0.15.0  gifti_0.8.0       
[25] yaml_2.3.7         xfun_0.40          fastmap_1.1.1      gridExtra_2.3     
[29] stringr_1.5.0      withr_2.5.1        knitr_1.44         xml2_1.3.5        
[33] generics_0.1.3     vctrs_0.6.4        grid_4.2.2         tidyselect_1.2.0  
[37] glue_1.6.2         R6_2.5.1           fansi_1.0.5        rmarkdown_2.25    
[41] sessioninfo_1.2.2  farver_2.1.1       magrittr_2.0.3     htmltools_0.5.6.1 
[45] splines_4.2.2      scales_1.3.0       abind_1.4-5        colorspace_2.1-0  
[49] labeling_0.4.3     utf8_1.2.3         stringi_1.7.12     munsell_0.5.0     
[53] R.oo_1.25.0   
r ggplot2 latex2exp
1个回答
0
投票

该错误似乎与 R 版本 4.2.2 有关,因为它确实适用于 4.3.3。

© www.soinside.com 2019 - 2024. All rights reserved.