2

我想用 ggplot 创建一个情节并用ggsave(). 作为我使用的设备cairo_pdf,因为我想嵌入字体。问题是,如果情节包含变音符号,我可以在 RStudio 中很好地创建情节,但如果我想保存它,我会收到以下错误:

grid.Call.graphics(C_text, as.graphicsAnnot(x$label), x$x, x$y, 中的错误:此系列/设备的度量信息不可用

这是一个演示问题的简短示例。该问题似乎是由变音符号和使用label_parsed.

library(ggplot2)

df <- data.frame(x = rnorm(10), 
                 y = rnorm(10), 
                 group = factor(rbinom(100, 1, .5), labels = c(expression("A^b"), expression("Ü"))))

ggplot(df, aes(x = x, y = y)) + geom_point() + facet_grid(. ~ group, labeller = label_parsed)
ggsave("test.pdf", device = cairo_pdf)

这是我的会话信息:

R version 3.6.3 (2020-02-29)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 10 x64 (build 18363)

Matrix products: default

locale:
[1] LC_COLLATE=German_Germany.1252  LC_CTYPE=German_Germany.1252    LC_MONETARY=German_Germany.1252
[4] LC_NUMERIC=C                    LC_TIME=German_Germany.1252    

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

other attached packages:
[1] ggplot2_3.3.0

loaded via a namespace (and not attached):
 [1] Rcpp_1.0.2       withr_2.1.2      assertthat_0.2.1 crayon_1.3.4     dplyr_0.8.3      grid_3.6.3      
 [7] R6_2.4.0         gtable_0.3.0     magrittr_1.5     scales_1.0.0     pillar_1.4.2     rlang_0.4.5     
[13] lazyeval_0.2.2   rstudioapi_0.10  tools_3.6.3      glue_1.3.1       purrr_0.3.3      munsell_0.5.0   
[19] compiler_3.6.3   pkgconfig_2.0.3  colorspace_1.4-1 tidyselect_0.2.5 tibble_2.1.3
4

0 回答 0