今天碰到一个奇怪的事情,我在Rsutdio (for windows) 中运行下面的代码之前都能正常做图的,今天运行的时候显示运行成功,但却不显示图像(无论是在rmarkdown中运行还是在console中)。
library(ggplot)
ggplot(mpg,aes(displ,hwy,color=drv))+
geom_point()+
scale_color_manual("驱动方式",
values=c("red","black","green"),
labels=c("四驱","前驱","后驱"))
几番尝试后把上面代码的中文都改为英文后就图形可以正常显示了。这是什么原因呢?有中文怎么才能正常显示呢?
我的系统环境为:
> sessionInfo()
R version 4.3.0 (2023-04-21 ucrt)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 11 x64 (build 22621)
Matrix products: default
locale:
[1] LC_COLLATE=Chinese (Simplified)_China.utf8
[2] LC_CTYPE=Chinese (Simplified)_China.utf8
[3] LC_MONETARY=Chinese (Simplified)_China.utf8
[4] LC_NUMERIC=C
[5] LC_TIME=Chinese (Simplified)_China.utf8
time zone: Asia/Shanghai
tzcode source: internal
attached base packages:
[1] stats graphics grDevices utils datasets methods base
other attached packages:
[1] showtext_0.9-6 showtextdb_3.0 sysfonts_0.8.8 knitr_1.43
[5] plotly_4.10.2 RMariaDB_1.2.2 dbplyr_2.3.2 flextable_0.9.1
[9] patchwork_1.1.2 lubridate_1.9.2 forcats_1.0.0 stringr_1.5.0
[13] dplyr_1.1.2 purrr_1.0.1 readr_2.1.4 tidyr_1.3.0
[17] tibble_3.2.1 ggplot2_3.4.2 tidyverse_2.0.0
loaded via a namespace (and not attached):
[1] tidyselect_1.2.0 viridisLite_0.4.2 farver_2.1.1
[4] blob_1.2.4 fastmap_1.1.1 lazyeval_0.2.2
[7] fontquiver_0.2.1 promises_1.2.0.1 digest_0.6.31
[10] timechange_0.2.0 mime_0.12 lifecycle_1.0.3
[13] ellipsis_0.3.2 gfonts_0.2.0 magrittr_2.0.3
[16] compiler_4.3.0 rlang_1.1.1 tools_4.3.0
[19] utf8_1.2.3 yaml_2.3.7 data.table_1.14.8
[22] askpass_1.1 labeling_0.4.2 htmlwidgets_1.6.2
[25] bit_4.0.5 curl_5.0.0 xml2_1.3.4
[28] httpcode_0.3.0 withr_2.5.0 grid_4.3.0
[31] fansi_1.0.4 gdtools_0.3.3 xtable_1.8-4
[34] colorspace_2.1-0 scales_1.2.1 crul_1.4.0
[37] cli_3.6.0 rmarkdown_2.22 crayon_1.5.2
[40] ragg_1.2.5 generics_0.1.3 rstudioapi_0.14
[43] httr_1.4.6 tzdb_0.4.0 readxl_1.4.2
[46] DBI_1.1.3 parallel_4.3.0 cellranger_1.1.0
[49] vctrs_0.6.2 jsonlite_1.8.4 fontBitstreamVera_0.1.1
[52] hms_1.1.3 bit64_4.0.5 systemfonts_1.0.4
[55] glue_1.6.2 stringi_1.7.12 gtable_0.3.3
[58] later_1.3.1 munsell_0.5.0 pillar_1.9.0
[61] htmltools_0.5.5 openssl_2.0.6 R6_2.5.1
[64] textshaping_0.3.6 vroom_1.6.3 evaluate_0.21
[67] shiny_1.7.4 fontLiberation_0.1.0 httpuv_1.6.11
[70] Rcpp_1.0.10 zip_2.3.0 uuid_1.1-0
[73] officer_0.6.2 xfun_0.39 pkgconfig_2.0.3