R在输出带有unicode的ggplot对象时崩溃

时间:2022-12-19 19:31:24

This code

这段代码

    data = data.frame(A=c(1:100), B=runif(100))
    library(ggplot2)
    ggplot(data, aes(A, B)) +
      geom_point() +
      ylab(expression(paste(delta^{13}~"C"~"VDPB (\u2030/)"))) +
      xlab("Time (Days)")
    ggsave("test.pdf", width=4, height=4, dpi=300, device=cairo_pdf)

crashes my R-Session with

我的R-Session崩溃

Error in grid.Call.graphics(L_text, as.graphicsAnnot(x$label), x$x, x$y,  : 
  Metric information not available for this family/device

although the expression is drawn correctly on the R-Studio graphical device.

尽管表达式在R-Studio图形设备上绘制正确。

After reviewing google, this problem is known, but i havent found a solution for it yet. Is there any way to circumvent this problem?

在回顾了谷歌之后,这个问题是已知的,但是我还没有找到解决方案。有什么办法可以绕过这个问题吗?

/edit: Session Info

/编辑:会话信息

    R version 3.3.3 (2017-03-06)
Platform: x86_64-w64-mingw32/x64 (64-bit)
Running under: Windows 7 x64 (build 7601) Service Pack 1

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] Cairo_1.5-9        rvg_0.1.2          scales_0.4.1       gridExtra_2.2.1    RColorBrewer_1.1-2
[6] reshape_0.8.6      ggplot2_2.2.1     

loaded via a namespace (and not attached):
 [1] Rcpp_0.12.9       digest_0.6.12     assertthat_0.1    R.methodsS3_1.7.1 grid_3.3.3       
 [6] plyr_1.8.4        gtable_0.2.0      gdtools_0.1.3     lazyeval_0.2.0    R.oo_1.21.0      
[11] R.utils_2.5.0     xml2_1.1.1        labeling_0.3      tools_3.3.3       munsell_0.4.3    
[16] colorspace_1.3-2  tibble_1.2      

1 个解决方案

#1


2  

Old (okay) answer: Change ggsave("test.pdf", width=4, height=4, dpi=300, device=cairo_pdf) to ggsave("test.pdf", width=4, height=4, dpi=300, device="pdf"). I just changed the device.

老的(好的)答案:更改ggsave(“测试”)。pdf", width=4, height=4, dpi=300,设备=cairo_pdf)到ggsave(test)。pdf",宽度=4,高度=4,dpi=300,设备="pdf")。我刚换了设备。

Edit: You can continue to use cairo_pdf as a device if you change your ylab creation to ylab(sprintf(paste(delta^{13}~"C"~"VDPB (\u2030/)"))) changing expression to sprintf. However, your y-label won't totally show up. it seems you're using some character that cairo_pdf doesn't like. So this could further solve the root of the problem.

编辑:您可以继续使用cairo_pdf作为设备如果你改变ylab创建ylab(sprintf(粘贴(△^ { 13 } ~“C”~“VDPB \ u2030 / ")))改变表达式sprintf。然而,你的y标签不会完全显示出来。看起来你用的是cairo_pdf不喜欢的字符。这可以进一步解决问题的根源。

#1


2  

Old (okay) answer: Change ggsave("test.pdf", width=4, height=4, dpi=300, device=cairo_pdf) to ggsave("test.pdf", width=4, height=4, dpi=300, device="pdf"). I just changed the device.

老的(好的)答案:更改ggsave(“测试”)。pdf", width=4, height=4, dpi=300,设备=cairo_pdf)到ggsave(test)。pdf",宽度=4,高度=4,dpi=300,设备="pdf")。我刚换了设备。

Edit: You can continue to use cairo_pdf as a device if you change your ylab creation to ylab(sprintf(paste(delta^{13}~"C"~"VDPB (\u2030/)"))) changing expression to sprintf. However, your y-label won't totally show up. it seems you're using some character that cairo_pdf doesn't like. So this could further solve the root of the problem.

编辑:您可以继续使用cairo_pdf作为设备如果你改变ylab创建ylab(sprintf(粘贴(△^ { 13 } ~“C”~“VDPB \ u2030 / ")))改变表达式sprintf。然而,你的y标签不会完全显示出来。看起来你用的是cairo_pdf不喜欢的字符。这可以进一步解决问题的根源。