library(igraph)
library(showtext)
g1 <- make_ring(10)
V(g1)$name <- c("中國", "美國", "Japan", "韓國", "俄羅斯", "德國", "法國", "英國", "印度", "Brazil")
plot(g1) + showtext.auto()
Showing English characters are OK, but failed in Chinese characters.
library(igraph)
library(showtext)
g1 <- make_ring(10)
V(g1)$name <- c("中國", "美國", "Japan", "韓國", "俄羅斯", "德國", "法國", "英國", "印度", "Brazil")
plot(g1) + showtext.auto()
Showing English characters are OK, but failed in Chinese characters.
@George_Nee! Thanks for your question and the reproducible example.
Unfortunately, or fortunately, your code seems to work on my machine:
library(igraph)
#>
#> Attaching package: 'igraph'
#> The following objects are masked from 'package:stats':
#>
#> decompose, spectrum
#> The following object is masked from 'package:base':
#>
#> union
library(showtext)
#> Loading required package: sysfonts
#> Loading required package: showtextdb
g1 <- make_ring(10)
V(g1)$name <- c("中國", "美國", "Japan", "韓國", "俄羅斯", "德國", "法國", "英國", "印度", "Brazil")
plot(g1) + showtext_auto()
#> integer(0)
Created on 2024-10-07 with reprex v2.1.0
sessioninfo::session_info()
#> ─ Session info ───────────────────────────────────────────────────────────────
#> setting value
#> version R version 4.4.1 (2024-06-14)
#> os Ubuntu 20.04.6 LTS
#> system x86_64, linux-gnu
#> ui X11
#> language en_US.utf8
#> collate en_US.utf8
#> ctype en_US.utf8
#> tz Europe/Paris
#> date 2024-10-07
#> pandoc 3.1.11 @ /usr/lib/rstudio/resources/app/bin/quarto/bin/tools/x86_64/ (via rmarkdown)
#>
#> ─ Packages ───────────────────────────────────────────────────────────────────
#> package * version date (UTC) lib source
#> cli 3.6.3 2024-06-21 [1] CRAN (R 4.4.0)
#> curl 5.2.3 2024-09-20 [1] CRAN (R 4.4.1)
#> digest 0.6.37 2024-08-19 [1] CRAN (R 4.4.0)
#> evaluate 1.0.0 2024-09-17 [1] CRAN (R 4.4.1)
#> fastmap 1.2.0 2024-05-15 [1] CRAN (R 4.4.0)
#> fs 1.6.4 2024-04-25 [1] CRAN (R 4.4.0)
#> glue 1.8.0 2024-09-30 [1] CRAN (R 4.4.1)
#> highr 0.11 2024-05-26 [1] CRAN (R 4.4.0)
#> htmltools 0.5.8.1 2024-04-04 [1] CRAN (R 4.4.0)
#> igraph * 2.1.0.9006 2024-10-07 [1] local
#> knitr 1.48 2024-07-07 [1] CRAN (R 4.4.0)
#> lifecycle 1.0.4 2023-11-07 [1] CRAN (R 4.4.0)
#> magrittr 2.0.3 2022-03-30 [1] CRAN (R 4.4.0)
#> pkgconfig 2.0.3 2019-09-22 [1] CRAN (R 4.4.0)
#> purrr 1.0.2 2023-08-10 [1] CRAN (R 4.4.0)
#> R.cache 0.16.0 2022-07-21 [1] CRAN (R 4.4.0)
#> R.methodsS3 1.8.2 2022-06-13 [1] CRAN (R 4.4.0)
#> R.oo 1.26.0 2024-01-24 [1] CRAN (R 4.4.0)
#> R.utils 2.12.3 2023-11-18 [1] CRAN (R 4.4.0)
#> reprex 2.1.0 2024-01-11 [1] CRAN (R 4.4.0)
#> rlang 1.1.4 2024-06-04 [1] CRAN (R 4.4.0)
#> rmarkdown 2.28 2024-08-17 [1] CRAN (R 4.4.0)
#> rstudioapi 0.16.0 2024-03-24 [1] CRAN (R 4.4.0)
#> sessioninfo 1.2.2 2021-12-06 [1] CRAN (R 4.4.0)
#> showtext * 0.9-7 2024-03-02 [1] CRAN (R 4.4.1)
#> showtextdb * 3.0 2020-06-04 [1] CRAN (R 4.4.1)
#> styler 1.10.3 2024-04-07 [1] CRAN (R 4.4.0)
#> sysfonts * 0.8.9 2024-03-02 [1] CRAN (R 4.4.1)
#> vctrs 0.6.5 2023-12-01 [1] CRAN (R 4.4.0)
#> withr 3.0.1 2024-07-31 [1] CRAN (R 4.4.0)
#> xfun 0.48 2024-10-03 [1] CRAN (R 4.4.1)
#> xml2 1.3.6 2023-12-04 [1] CRAN (R 4.4.0)
#> yaml 2.3.10 2024-07-26 [1] CRAN (R 4.4.0)
#>
#> [1] /home/maelle/R/x86_64-pc-linux-gnu-library/4.4
#> [2] /usr/local/lib/R/site-library
#> [3] /usr/lib/R/site-library
#> [4] /usr/lib/R/library
#>
#> ──────────────────────────────────────────────────────────────────────────────
Which versions of R, igraph and showtext are you using?
This is not specific to igraph, but a general R issue. I also see the same problem on macOS with R 4.4.1, running in RStudio.
This advice worked for me, but I needed to restart RStudio after changing the graphics backend:
I’ll note that these are not English characters, but Roman letters, used to write many, many languages around the world besides English