为什么表情符号在 ggplot 中无法正确渲染?

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

我多次未能将表情符号合并到 ggplot 中,并且在下面包含一个基本示例,我只是尝试将表情符号添加到空白图上的两个轴标题。感谢任何和所有的帮助:

library(tidyverse)
#remotes::install_github("hadley/emo")
library(emo)

ggplot() +
  xlab(paste0('Mileage', emo::ji("fuel_pump"))) +
  ylab(paste0('Vehicle', emo::ji("car"))) +
  theme(text = element_text(family = "Trebuchet MS"))

这产生:

我也尝试过使用

emojifont
包。

library(emojifont)

ggplot() +
  xlab(paste0('Mileage', emojifont::emoji("fuel_pump"))) +
  ylab(paste0('Vehicle', emojifont::emoji("car"))) +
  theme(text = element_text(family = "Trebuchet MS"))

第二次尝试时,不仅表情符号无法正确渲染,而且我收到以下警告,并且我选择的字体系列被替换为通用字体:“1:在 grid.Call(C_textBounds, as.graphicsAnnot(x$label) 中), x$x, x$y, : 未找到字体系列“Trebuchet MS”,将使用“wqy-microhei”代替”

最后包括以下

sessionInfo()

R版本4.3.3 (2024-02-29) 平台:aarch64-apple-darwin20(64位) 运行环境:macOS Sonoma 14.4.1

矩阵产品:默认 BLAS:/System/Library/Frameworks/Accelerate.framework/Versions/A/Frameworks/vecLib.framework/Versions/A/libBLAS.dylib LAPACK:/Library/Frameworks/R.framework/Versions/4.3-arm64/Resources/lib/libRlapack.dylib; LAPACK 版本 3.11.0

区域设置: 1 en_US.UTF-8/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8

时区: America/Los_Angeles tzcode 来源:内部

附加基础包: 1 统计图形 grDevices utils 数据集 方法基础

其他附件包: 1scales_1.3.0 lubridate_1.9.3 forcats_1.0.0 stringr_1.5.1 dplyr_1.1.4 purrr_1.0.2
[7] readr_2.1.5 tidyr_1.3.1 tibble_3.2.1 ggplot2_3.5.0 tidyverse_2.0.0 RPostgres_1.4.6 [13] emo_0.0.0.9000

通过命名空间加载(且未附加): 1 cfbfastR_1.9.0 DBI_1.2.2 远程_2.5.0 writexl_1.5.0 rlang_1.1.3
[6] magrittr_2.0.3 Snakecase_0.11.1furrr_0.3.1compiler_4.3.3mgcv_1.9-1
[11] callr_3.7.6 png_0.1-8 systemfonts_1.0.6 vctrs_0.6.5 reshape2_1.4.4
[16] sysfonts_0.8.9 rvest_1.0.4 profvis_0.3.8 crayon_1.5.2 pkgconfig_2.0.3
[21] fastmap_1.1.1 backports_1.4.1 ellipsis_0.3.2 labels_0.4.3 utf8_1.2.4
[26] Promise_1.2.1 rmarkdown_2.26 sessioninfo_1.2.2 tzdb_0.4.0 ps_1.7.6
[31] bit_4.0.5 xfun_0.43 showtext_0.9-7 cachem_1.0.8 jsonlite_1.8.8
[36] blob_1.2.4 后来_1.3.2 jpeg_0.1-10 broom_1.0.5 并行_4.3.3
[41] R6_2.5.1 stringi_1.8.3 espncrapeR_0.8.0parallelly_1.37.1 pkgload_1.3.4
[46]assertthat_0.2.1 Rcpp_1.0.12 knit_1.45 usethis_2.2.3 pacman_0.5.1
[51] nnet_7.3-19 Matrix_1.6-5 httpuv_1.6.15 splines_4.3.3 timechange_0.3.0
[56] tidyselect_1.2.1 rstudioapi_0.16.0 yaml_2.3.8 codetools_0.2-19 miniUI_0.1.1.1
[61] websocket_1.4.1curl_5.2.1processx_3.8.4listenv_0.9.1pkgbuild_1.4.4
[66]lattice_0.22-6 plyr_1.8.9 withr_3.0.0shiny_1.8.1evaluate_0.23
[71] desc_1.4.3 future_1.33.1 RcppParallel_5.1.7 urlchecker_1.0.1 xml2_1.3.6
[76]pillar_1.9.0 generics_0.1.3 chromote_0.2.0 hms_1.1.3 munsell_0.5.0
[81] globals_0.16.3 xtable_1.8-4glue_1.7.0 janitor_2.2.0 mlbplotR_1.1.0
[86]tools_4.3.3 data.table_1.15.2 fs_1.6.3 grid_4.3.3 devtools_2.4.5
[91] colorspace_2.1-0 nlme_3.1-164 patchwork_1.2.0 showtextdb_3.0 proto_1.0.0
[96]棒球r_1.6.0 cli_3.6.2 fansi_1.0.6 gt_0.10.1 V8_4.4.2
[101] gtable_0.3.4 摘要_0.6.35 farver_2.1.1 htmlwidgets_1.6.4 memoise_2.0.1
[106]htmltools_0.5.8lifecycle_1.0.4httr_1.4.7mime_0.12bit64_4.0.5

r ggplot2 fonts axis emoji
1个回答
0
投票

在Rstudio中;将您的图形设备后端更改为“AGG”

工具 > 全局选项 > 图形 >>> AGG

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